1. class SplDoublyLinkedList implements Iterator, Traversable, Countable, ArrayAccess {
  2. const IT_MODE_LIFO = 2;
  3. const IT_MODE_FIFO = 0;
  4. const IT_MODE_DELETE = 1;
  5. const IT_MODE_KEEP = 0;
  6.  
  7. /**
    * Add/insert a new value at the specified index
  8. * @param mixed $index The index where the new value is to be inserted.
  9. * @param mixed $newval The new value for the index.
  10. * @link http://php.net/spldoublylinkedlist.add
  11. * @return void
  12. * @since 5.5.0
  13. */
  14. public function add($index, $newval) {}
  15.  
  16. /**
  17. * Pops a node from the end of the doubly linked list
  18. * @link http://php.net/manual/en/spldoublylinkedlist.pop.php
  19. * @return mixed The value of the popped node.
  20. * @since 5.3.0
  21. */
  22. public function pop () {}
  23.  
  24. /**
  25. * Shifts a node from the beginning of the doubly linked list
  26. * @link http://php.net/manual/en/spldoublylinkedlist.shift.php
  27. * @return mixed The value of the shifted node.
  28. * @since 5.3.0
  29. */
  30. public function shift () {}
  31.  
  32. /**
  33. * Pushes an element at the end of the doubly linked list
  34. * @link http://php.net/manual/en/spldoublylinkedlist.push.php
  35. * @param mixed $value <p>
  36. * The value to push.
  37. * </p>
  38. * @return void
  39. * @since 5.3.0
  40. */
  41. public function push ($value) {}
  42.  
  43. /**
  44. * Prepends the doubly linked list with an element
  45. * @link http://php.net/manual/en/spldoublylinkedlist.unshift.php
  46. * @param mixed $value <p>
  47. * The value to unshift.
  48. * </p>
  49. * @return void
  50. * @since 5.3.0
  51. */
  52. public function unshift ($value) {}
  53.  
  54. /**
  55. * Peeks at the node from the end of the doubly linked list
  56. * @link http://php.net/manual/en/spldoublylinkedlist.top.php
  57. * @return mixed The value of the last node.
  58. * @since 5.3.0
  59. */
  60. public function top () {}
  61.  
  62. /**
  63. * Peeks at the node from the beginning of the doubly linked list
  64. * @link http://php.net/manual/en/spldoublylinkedlist.bottom.php
  65. * @return mixed The value of the first node.
  66. * @since 5.3.0
  67. */
  68. public function bottom () {}
  69.  
  70. /**
  71. * Counts the number of elements in the doubly linked list.
  72. * @link http://php.net/manual/en/spldoublylinkedlist.count.php
  73. * @return int the number of elements in the doubly linked list.
  74. * @since 5.3.0
  75. */
  76. public function count () {}
  77.  
  78. /**
  79. * Checks whether the doubly linked list is empty.
  80. * @link http://php.net/manual/en/spldoublylinkedlist.isempty.php
  81. * @return bool whether the doubly linked list is empty.
  82. * @since 5.3.0
  83. */
  84. public function isEmpty () {}
  85.  
  86. /**
  87. * Sets the mode of iteration
  88. * @link http://php.net/manual/en/spldoublylinkedlist.setiteratormode.php
  89. * @param int $mode <p>
  90. * There are two orthogonal sets of modes that can be set:
  91. * </p>
  92. * The direction of the iteration (either one or the other):
  93. * <b>SplDoublyLinkedList::IT_MODE_LIFO</b> (Stack style)
  94. * @return void
  95. * @since 5.3.0
  96. */
  97. public function setIteratorMode ($mode) {}
  98.  
  99. /**
  100. * Returns the mode of iteration
  101. * @link http://php.net/manual/en/spldoublylinkedlist.getiteratormode.php
  102. * @return int the different modes and flags that affect the iteration.
  103. * @since 5.3.0
  104. */
  105. public function getIteratorMode () {}
  106.  
  107. /**
  108. * Returns whether the requested $index exists
  109. * @link http://php.net/manual/en/spldoublylinkedlist.offsetexists.php
  110. * @param mixed $index <p>
  111. * The index being checked.
  112. * </p>
  113. * @return bool true if the requested <i>index</i> exists, otherwise false
  114. * @since 5.3.0
  115. */
  116. public function offsetExists ($index) {}
  117.  
  118. /**
  119. * Returns the value at the specified $index
  120. * @link http://php.net/manual/en/spldoublylinkedlist.offsetget.php
  121. * @param mixed $index <p>
  122. * The index with the value.
  123. * </p>
  124. * @return mixed The value at the specified <i>index</i>.
  125. * @since 5.3.0
  126. */
  127. public function offsetGet ($index) {}
  128.  
  129. /**
  130. * Sets the value at the specified $index to $newval
  131. * @link http://php.net/manual/en/spldoublylinkedlist.offsetset.php
  132. * @param mixed $index <p>
  133. * The index being set.
  134. * </p>
  135. * @param mixed $newval <p>
  136. * The new value for the <i>index</i>.
  137. * </p>
  138. * @return void
  139. * @since 5.3.0
  140. */
  141. public function offsetSet ($index, $newval) {}
  142.  
  143. /**
  144. * Unsets the value at the specified $index
  145. * @link http://php.net/manual/en/spldoublylinkedlist.offsetunset.php
  146. * @param mixed $index <p>
  147. * The index being unset.
  148. * </p>
  149. * @return void
  150. * @since 5.3.0
  151. */
  152. public function offsetUnset ($index) {}
  153.  
  154. /**
  155. * Rewind iterator back to the start
  156. * @link http://php.net/manual/en/spldoublylinkedlist.rewind.php
  157. * @return void
  158. * @since 5.3.0
  159. */
  160. public function rewind () {}
  161.  
  162. /**
  163. * Return current array entry
  164. * @link http://php.net/manual/en/spldoublylinkedlist.current.php
  165. * @return mixed The current node value.
  166. * @since 5.3.0
  167. */
  168. public function current () {}
  169.  
  170. /**
  171. * Return current node index
  172. * @link http://php.net/manual/en/spldoublylinkedlist.key.php
  173. * @return mixed The current node index.
  174. * @since 5.3.0
  175. */
  176. public function key () {}
  177.  
  178. /**
  179. * Move to next entry
  180. * @link http://php.net/manual/en/spldoublylinkedlist.next.php
  181. * @return void
  182. * @since 5.3.0
  183. */
  184. public function next () {}
  185.  
  186. /**
  187. * Move to previous entry
  188. * @link http://php.net/manual/en/spldoublylinkedlist.prev.php
  189. * @return void
  190. * @since 5.3.0
  191. */
  192. public function prev () {}
  193.  
  194. /**
  195. * Check whether the doubly linked list contains more nodes 当前指针处元素是否有效
  196. * @link http://php.net/manual/en/spldoublylinkedlist.valid.php
  197. * @return bool true if the doubly linked list contains any more nodes, false otherwise.
  198. * @since 5.3.0
  199. */
  200. public function valid () {}
  201.  
  202. /**
  203. * Unserializes the storage
  204. * @link http://php.net/manual/ru/spldoublylinkedlist.serialize.php
  205. * @param string $serialized The serialized string.
  206. * @return void
  207. * @since 5.4.0
  208. */
  209. public function unserialize($serialized) {}
  210.  
  211. /**
  212. * Serializes the storage
  213. * @link http://php.net/manual/ru/spldoublylinkedlist.unserialize.php
  214. * @return string The serialized string.
  215. * @since 5.4.0
  216. */
  217. public function serialize () {}
  218.  
  219. }

用例

  1. <?php
  2. header("Content-type: text/html; charset=gb2312");
  3. $doubly=new SplDoublyLinkedList();
  4. $doubly->push('a');
  5. $doubly->push('b');
  6. $doubly->push('c');
  7. $doubly->push('d');
  8. $doubly->add(1,'e');
  9.  
  10. echo 'Original:'."\n";
  11. var_dump($doubly);
  12.  
  13. echo 'FIFO|KEEP:'."\n";
  14. $doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP);
  15. $doubly->rewind();
  16. foreach($doubly as $key=>$value)
  17. {
  18. echo $key.' '.$value."\n";
  19. }
  20.  
  21. echo 'LIFO|KEEP:'."\n";
  22. $doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP);
  23. $doubly->rewind();
  24. foreach($doubly as $key=>$value)
  25. {
  26. echo $key.' '.$value."\n";
  27. }
  28.  
  29. echo 'LIFO|DELETE:'."\n";
  30. $doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_DELETE);
  31. $doubly->rewind();
  32. foreach($doubly as $key=>$value)
  33. {
  34. if($key == 1) break;
  35. echo $key.' '.$value."\n";
  36. }
  37. echo 'List after Delete'."\n";
  38. var_dump($doubly);
  39. ?>

PHP标准库(SPL)- SplDoublyLinkedList类(双向链表)的更多相关文章

  1. PHP 标准库 SPL 之数据结构栈(SplStack)简单实践

    PHP 5.3.0 版本及以上的堆栈描述可以使用标准库 SPL 中的 SplStack class,SplStack 类继承双链表 ( SplDoublyLinkedList ) 实现栈. 代码: & ...

  2. php标准库spl栈SplStack如何使用?

    php标准库spl栈SplStack如何使用? 一.总结 php标准库spl栈SplStack介绍.(SplStack类)(各种方法都支持) 1.SplStack类:$stack = new SplS ...

  3. C++解析(18):C++标准库与字符串类

    0.目录 1.C++标准库 2.字符串类 3.数组操作符的重载 4.小结 1.C++标准库 有趣的重载--操作符 << 的原生意义是按位左移,例:1 << 2;,其意义是将整数 ...

  4. C 和 C++ 的标准库分别有自己的 locale 操作方法,C 标准库的 locale 设定函数是 setlocale(),而 C++ 标准库有 locale 类和流对象的 imbue() 方法(gcc使用zh_CN.GBK,或者zh_CN.UTF-8,VC++使用Chinese_People's Republic of China.936或者65001.)

    转自:http://zyxhome.org/wp/cc-prog-lang/c-stdlib-setlocale-usage-note/ [在此向原文作者说声谢谢!若有读者看到文章转载时请写该转载地址 ...

  5. PHP标准库 (SPL) 笔记

    简介 SPL是Standard PHP Library(PHP标准库)的缩写. The Standard PHP Library (SPL) is a collection of interfaces ...

  6. 【夯实PHP基础】PHP标准库 SPL

    PHP SPL笔记 这几天,我在学习PHP语言中的SPL. 这个东西应该属于PHP中的高级内容,看上去很复杂,但是非常有用,所以我做了长篇笔记.不然记不住,以后要用的时候,还是要从头学起. 由于这是供 ...

  7. PHP标准库 SPL

    PHP SPL笔记 这几天,我在学习PHP语言中的SPL. 这个东西应该属于PHP中的高级内容,看上去很复杂,但是非常有用,所以我做了长篇笔记.不然记不住,以后要用的时候,还是要从头学起. 由于这是供 ...

  8. PHP标准库SPL

    SPL是Standard PHP Library(PHP标准库)的缩写.用来解决典型(常见)问题(common problems)的一组接口与类的集合 典型问题(common problems) - ...

  9. 基于标准库的string类实现简单的字符串替换

    感觉基本功还是不扎实,虽然能做些程序但是现在看来我还是个初学者(primer),试着完成习题结果还得修修改改. 废话不多说,实现功能很简单,<C++ Primer>9.5.2节习题. // ...

  10. Python - 标准库部分函数、类的大致实现(持续更新)

    all() def all(iterable): for element in iterbale: if not element: return False return True any() def ...

随机推荐

  1. MySQL show master / slave status 命令参数

    一.show master status 二.show slave status Slave_IO_State SHOW PROCESSLIST输出的State字段的拷贝.SHOW PROCESSLI ...

  2. LPC1788系统时钟初始化

    #ifndef __SYS_H_ #define __SYS_H_ #include "common.h" #define SystemCoreClock  120000000  ...

  3. JNI错误总结(转)

    源:JNI错误总结 最近公司里要用JNI技术,用java去调用已经写好的本地DLL库.之前自己也没接触过相关技术,其中花了大部分时间在调试改错上面,网上对于错误的解决方案也不多,现在项目接近完工,自己 ...

  4. X-007 FriendlyARM tiny4412 u-boot移植之内存初始化

    <<<<<<<<<<<<<<<<<<<<<<<<< ...

  5. UVa 324 - Factorial Frequencies

    题目大意:给一个数n,统计n的阶乘中各个数字出现的次数.用java的大数做. import java.io.*; import java.util.*; import java.math.*; cla ...

  6. builds error

    使用cocoapods 出现Undefined symbols for architecture i386: _OBJC_CLASS_$_XXXXXXX", referenced from: ...

  7. BZOJ2064: 分裂

    2064: 分裂 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 360  Solved: 220[Submit][Status][Discuss] De ...

  8. sysctl.conf和limit.conf备忘待查

    #################################limits.conf设置################################### #修改最大进程和最大文件打开数限制v ...

  9. Python科学计算之Pandas

    Reference: http://mp.weixin.qq.com/s?src=3&timestamp=1474979163&ver=1&signature=wnZn1UtW ...

  10. [NOI2011]阿狸的打字机(好题!!!!)

    2785: [NOI2011]阿狸的打字机 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 7  Solved: 3[Submit][Status][We ...