php标准库 SPL 数据结构之-----SplDoublyLinkedList(双向链表)

WBOY
Release: 2016-08-08 09:27:44
Original
1126 people have browsed it
          $spl=new SplDoublyLinkedList();  //实例化双向链表的对象
          $spl->push("sdfsaf");	          //添加到链表的顶部(top)(尾部)
	  $spl->push(111);
	  $spl->push('1');
	  $spl->unshift("100");        //添加到链表的底部(bottom)(头部) 前值在双向链表的开

         $spl->shift();   //删除bottom(头部)所在位置的值
         $spl->pop();    // 弹出top的值   

         $spl->top();    //获取顶部(尾部)的元素
         $spl->count();    //节点的 个数
         $spl->isEmpty();  // 当前是否为空,为空返回true
        
          $spl->rewind();     //移动到bottom(头部)位置
          $spl->current();  // 获取当前节点的值

           $spl->next();   //向下移动节点
           $spl->prev();   //返回上一个节点 
          
           //循环遍历链表
           
               $spl->rewind();
                 while($name=$spl->current()){
                       echo $name."\n";
                      $spl->next();
                 }
            /************************************************************************/
              
                for ($spl->rewind(); $spl->valid(); $spl->next()) {
                       echo $spl->current()."\n";
               }



             var_dump($spl->valid()); //如果节点是有效节点返回true,否则返回false
            
      // 注意 :  当$spl->current(), $spl->valid()之前必须$spl->rewind(); 否则指向空节点

 
Copy after login

以上就介绍了php标准库 SPL 数据结构之-----SplDoublyLinkedList(双向链表),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!