真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

數(shù)據(jù)結(jié)構(gòu)之隊(duì)列——順序存儲(chǔ)結(jié)構(gòu)(php代碼實(shí)現(xiàn)——方法三)

SqArr=array();
        $this->front=0;
        $this->rear=0;
    }

    //銷毀隊(duì)列
    public function DestroyQueue(){
        $this->SqArr=null;
        $this->front=$this->rear=0;
    }

    //清空隊(duì)列
    public function ClearQueue(){
        $this->SqArr=array();
        $this->front=$this->rear=0;
    }

    //隊(duì)列是否為空
    public function QueueEmpty(){
        if($this->front==$this->rear){
            return 'Null';
        }else{
            return 'No Null';
        }
    }

    //隊(duì)列的長(zhǎng)度
    public function QueueLength(){
        return ($this->rear - $this->front + self::ARR_MAX) % self::ARR_MAX;
    }

    //取得隊(duì)頭元素
    public function GetHead(){
        if($this->rear==$this->front){
            return 'ERROR';
        }
        return $this->SqArr[$this->front];
    }

    //從隊(duì)尾摻入元素
    public function EnQueue($elem){
        $tail=($this->rear + 1)%self::ARR_MAX;//如果此值等于頭元素說(shuō)明隊(duì)列已滿
        if($tail == $this->front){
            return 'ERROR';
        }
        $this->SqArr[$this->rear]=$elem;
        $this->rear=($this->rear+1)%self::ARR_MAX;
        return 'OK';
    }

    //從隊(duì)頭刪除元素
    public function DeQueue(){
        if($this->rear==$this->front){
            return 'ERROR';
        }
        unset($this->SqArr[$this->front]);
        $this->front=($this->front + 1)%self::ARR_MAX;
        return 'OK';
    }

    //遍歷隊(duì)元素
    public function QueueTraverse(){
        $arr=array();
        for($i=0;$iSqArr[$i])){
                $arr[]=$this->SqArr[$i];
            }
        }
        return $arr;
    }
    //或者
    public function QueueTraverse2(){
        $arr=array();
        $i=$this->front;
        while($i != $this->rear){
            $arr[]=$this->SqArr[$i];
            $i=($i+1)%self::ARR_MAX;
        }
        return $arr;
    }
}

本文題目:數(shù)據(jù)結(jié)構(gòu)之隊(duì)列——順序存儲(chǔ)結(jié)構(gòu)(php代碼實(shí)現(xiàn)——方法三)
文章源于:http://weahome.cn/article/pjgpie.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部