Skip to content

Instantly share code, notes, and snippets.

@NCatalani
Last active April 3, 2021 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NCatalani/caf6cc22b84593bc284f5a837465866f to your computer and use it in GitHub Desktop.
Save NCatalani/caf6cc22b84593bc284f5a837465866f to your computer and use it in GitHub Desktop.
Simple queue abstraction for PHP
<?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