数据结构之队列——顺序存储结构(php代码实现——方法二)
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; } }
当前题目:数据结构之队列——顺序存储结构(php代码实现——方法二)
URL网址:http://pwwzsj.com/article/gehscd.html