Skip to content

Instantly share code, notes, and snippets.

@zachflower
Last active August 24, 2016 13:24
Show Gist options
  • Save zachflower/d7fcee049eea9971404a to your computer and use it in GitHub Desktop.
Save zachflower/d7fcee049eea9971404a 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