Home > Backend Development > PHP Tutorial > PHP standard library SPL data structure -----SplDoublyLinkedList (doubly linked list)

PHP standard library SPL data structure -----SplDoublyLinkedList (doubly linked list)

WBOY
Release: 2016-08-08 09:27:44
Original
1287 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

The above introduces the SPL data structure of the PHP standard library -----SplDoublyLinkedList (doubly linked list), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template