Skip to content

Instantly share code, notes, and snippets.

@mikemadisonweb
Forked from zachflower/Queue.class.php
Created August 24, 2016 13:24
Show Gist options
  • Select an option

  • Save mikemadisonweb/d58879b9b81d1b6ef90a4f9abca60960 to your computer and use it in GitHub Desktop.

Select an option

Save mikemadisonweb/d58879b9b81d1b6ef90a4f9abca60960 to your computer and use it in GitHub Desktop.
PHP implementation of a queue.
<?php
// http://www.cplusplus.com/reference/queue/queue/
class Queue {
private $_queue = array();
public function size() {
return count($this->_queue);
}
public function front() {
return end($this->_queue);
}
public function back() {
return reset($this->_queue);
}
public function push($value = NULL) {
array_unshift($this->_queue, $value);
}
public function pop() {
return array_pop($this->_queue);
}
public function isEmpty() {
return empty($this->_queue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment