• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    php 数据结构之链表队列

    php 链表队列

    实例代码:

    class Queue{ 
      
      private $last; 
      private $first; 
      private $oldfirst; 
      private static $n=0; 
       
      public function __construct(){ 
        $this->last   = null; 
        $this->first  = null; 
        $this->oldfirst = null; 
      } 
       
      public function push($item){ 
        $this->oldfirst = $this->last; 
        $this->last = new Node(); 
        $this->last->item = $item; 
        $this->last->next = null; 
        if(empty($this->first)){ 
          $this->first = $this->last; 
        }else{ 
          $this->oldfirst->next = $this->last; 
        } 
        self::$n++; 
      } 
       
      public function pop(){ 
        if(self::$n0){ 
          return null; 
        } 
        $item = $this->first->item; 
        $this->first = $this->first->next; 
        self::$n--; 
        return $item; 
      } 
       
    } 
     
    class Node{ 
      public $item; 
      public $next; 
    } 
     
    $Queue = new Queue(); 
    $Queue->push("a"); 
    $Queue->push("b"); 
    $Queue->push("c"); 
    echo $Queue->pop().PHP_EOL; 
    echo $Queue->pop().PHP_EOL; 
    echo $Queue->pop().PHP_EOL; 
    echo $Queue->pop().PHP_EOL;
    
    

    如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

    您可能感兴趣的文章:
    • PHP双向链表定义与用法示例
    • php实现单链表的实例代码
    • 浅谈PHP链表数据结构(单链表)
    • PHP小教程之实现双向链表
    • PHP环形链表实现方法示例
    • PHP中模拟链表和链表的基本操作示例
    • PHP简单实现循环链表功能示例
    • PHP实现链表的定义与反转功能示例
    上一篇:PHP实现的贪婪算法实例
    下一篇:php 二维数组快速排序算法的实现代码
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    php 数据结构之链表队列 php,数据结构,之链,表,队列,