成都创新互联网站制作重庆分公司

数据结构之队列——顺序存储结构(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://cxhlcq.com/article/gehscd.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部