重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
SqArr=array(); $this->front=0; $this->rear=0; } //销毁队列 public function DestroyQueue(){ $this->SqArr=null; $this->front=0; $this->rear=0; } //清空队列 public function ClearQueue(){ $this->SqArr=array(); $this->front=$this->rear=0; } //判断队列是否为空 public function QueueEmpty(){ if($this->front==$this->rear){ return 'Null'; }else{ return 'No Null'; } } //取得队头元素 public function GetHead(){ if($this->front == $this->rear){ return 'ERROR'; } return $this->SqArr[$this->front]; } //队列的长度 public function QueueLenghth(){ return $this->rear-$this->front; } //从队尾插入元素 public function EnQueue($elem){ $this->SqArr[$this->rear++]=$elem; } //从队头删除元素 public function DeQueue(){ if($this->front==$this->rear){ return 'ERROR'; } unset($this->SqArr[$this->front]); $this->front++; return 'OK'; } //遍历队列元素 public function QueueTraverse(){ $arr=array(); for($i=$this->front;$i<$this->rear;$i++){ $arr[]=$this->SqArr[$i]; } return $arr; } }