用PHP实现一个双向队列,具体代码实现如下:
class Queue {
// 存储
protected $storage = array();
// 入头
public function unshift($element) {
return array_unshift($this->storage,$element);
}
// 入尾
public function push($element) {
return array_push($this->storage,$element);
}
//出头
public function shift() {
return array_shift($this->storage);
}
// 出尾
public function pop() {
return array_pop($this->storage);
}
// 长度
public function length() {
return count($this->storage);
}
}