数据结构之队列——链式存储结构(php代码实现)-创新互联

data=$data;         $this->next=null;     } } class LinkQueue{ //链队列包含头结点,实例化时,此队列为空     private $data;     private $next;     private $front;//指向头结点     private $rear;//指向尾结点 //    private $length;     public function __construct(){         $this->data=null;         $this->next=null;         $this->front=$this; //指向头结点         $this->rear=$this;//指向头结点 //        $this->length=0;     }     //销毁队列     public function DestroyQueue(){         while($this->front){ //销毁首先是从头结点开始             $this->rear=$this->front->next;             unset($this->front);             $this->front=$this->rear;         }     }     //清空队列     public function ClearQueue(){         $p=$this->front->next;         while($p){             $q=$p->next;             unset($p);             $p=$q;         }         $this->front->next=null;         $this->rear=$this->front;     }     //队列是否为空     public function QueueEmpty(){         if($this->front==$this->rear){             return 'Null';         }else{             return 'No Null';         }     }     //队列的长度     public function QueueLength(){         $p=$this->front;         $i=0;         while($p != $this->rear){             $i++;             $p=$p->next;         }         return $i; //        return $this->length;     }     //取得队头元素     public function GetHead(){         if($this->front==$this->rear){             return 'ERROR';         }         return $this->front->next->data;     }     //从队尾插入元素     public function EnQueue(){         $node=new QNode(mt_rand(100,200));         $node->next=$this->rear->next;         $this->rear->next=$node;         $this->rear=$node;         $this->length++;     }     //从队头删除元素     public function DeQueue(){         if($this->front==$this->rear){             return 'ERROR';         }         $p=$this->front->next;         unset($this->front->next);         $this->front->next=$p->next;         if($this->rear==$p){ //如果只有一个元素那么,为指针就需要变化了。             $this->rear=$this->front;         }         $this->length--;         return 'OK';     }     //遍历队列元素     public function QueueTraverse(){         if($this->front==$this->rear){             return 'ERROR';         }         $arr=array();         $p=$this->front->next;         while($p){             $arr[]=$p->data;             $p=$p->next;         }         return $arr;     } }

为东宝等地区用户提供了全套网页设计制作服务,及东宝网站建设行业解决方案。主营业务为做网站、成都网站制作、东宝网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:数据结构之队列——链式存储结构(php代码实现)-创新互联
当前地址:http://lszwz.com/article/pgihc.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款