Last active
April 3, 2021 22:59
-
-
Save NCatalani/caf6cc22b84593bc284f5a837465866f to your computer and use it in GitHub Desktop.
Simple queue abstraction for PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Queue; | |
class Queue { | |
private $queue; | |
function __construct() { | |
$this->initQueue(); | |
} | |
private function initQueue() { | |
$this->queue = Array(); | |
} | |
public function enqueue($element) { | |
$this->queue[] = $element; | |
} | |
public function dequeue() { | |
$aux = array_reverse($this->queue); | |
$element = array_pop($aux); | |
$this->queue = array_reverse($aux); | |
return $element; | |
} | |
public function isEmpty() { | |
if (empty($this->queue)) return TRUE; | |
return FALSE; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment