<?php
class node{
public $value; public function __construct($value){ $this->value = $value; }}class queue{
public $head;
public $last; public $queuelist; public $size = 0;//出队列
public function dequeue(){ if(0 == $this->size){ return ; exit('the queue is empty'); } $current = $this->head; array_shift($this->queuelist); $this->head = current($this->queuelist); $this->size--; return $current; } //入队列 public function enqueue($value){$node = new node($value);
$this->queuelist[] = $node; if( 0 == $this->size){ $this->head = $node; } $this->last = $node ; $this->size++;}
public function size(){
return $this->size; }}
$queue = new queue();for($i=0;$i<10;$i++){
$queue->enqueue($i);} while($value = $queue->dequeue()){ var_dump($value);}