PHP標準庫(SPL)- SplDoublyLinkedList類(雙向鏈表)

來源:互聯網
上載者:User

標籤:shift   var_dump   node   key   previous   echo   list   ora   5.5   

class SplDoublyLinkedList implements Iterator, Traversable, Countable, ArrayAccess {        const IT_MODE_LIFO = 2;        const IT_MODE_FIFO = 0;        const IT_MODE_DELETE = 1;        const IT_MODE_KEEP = 0;        /**
* Add/insert a new value at the specified index * @param mixed $index The index where the new value is to be inserted. * @param mixed $newval The new value for the index. * @link http://php.net/spldoublylinkedlist.add * @return void * @since 5.5.0
*/ public function add($index, $newval) {} /** * Pops a node from the end of the doubly linked list * @link http://php.net/manual/en/spldoublylinkedlist.pop.php * @return mixed The value of the popped node. * @since 5.3.0 */ public function pop () {} /** * Shifts a node from the beginning of the doubly linked list * @link http://php.net/manual/en/spldoublylinkedlist.shift.php * @return mixed The value of the shifted node. * @since 5.3.0 */ public function shift () {} /** * Pushes an element at the end of the doubly linked list * @link http://php.net/manual/en/spldoublylinkedlist.push.php * @param mixed $value <p> * The value to push. * </p> * @return void * @since 5.3.0 */ public function push ($value) {} /** * Prepends the doubly linked list with an element * @link http://php.net/manual/en/spldoublylinkedlist.unshift.php * @param mixed $value <p> * The value to unshift. * </p> * @return void * @since 5.3.0 */ public function unshift ($value) {} /** * Peeks at the node from the end of the doubly linked list * @link http://php.net/manual/en/spldoublylinkedlist.top.php * @return mixed The value of the last node. * @since 5.3.0 */ public function top () {} /** * Peeks at the node from the beginning of the doubly linked list * @link http://php.net/manual/en/spldoublylinkedlist.bottom.php * @return mixed The value of the first node. * @since 5.3.0 */ public function bottom () {} /** * Counts the number of elements in the doubly linked list. * @link http://php.net/manual/en/spldoublylinkedlist.count.php * @return int the number of elements in the doubly linked list. * @since 5.3.0 */ public function count () {} /** * Checks whether the doubly linked list is empty. * @link http://php.net/manual/en/spldoublylinkedlist.isempty.php * @return bool whether the doubly linked list is empty. * @since 5.3.0 */ public function isEmpty () {} /** * Sets the mode of iteration * @link http://php.net/manual/en/spldoublylinkedlist.setiteratormode.php * @param int $mode <p> * There are two orthogonal sets of modes that can be set: * </p> * The direction of the iteration (either one or the other): * <b>SplDoublyLinkedList::IT_MODE_LIFO</b> (Stack style) * @return void * @since 5.3.0 */ public function setIteratorMode ($mode) {} /** * Returns the mode of iteration * @link http://php.net/manual/en/spldoublylinkedlist.getiteratormode.php * @return int the different modes and flags that affect the iteration. * @since 5.3.0 */ public function getIteratorMode () {} /** * Returns whether the requested $index exists * @link http://php.net/manual/en/spldoublylinkedlist.offsetexists.php * @param mixed $index <p> * The index being checked. * </p> * @return bool true if the requested <i>index</i> exists, otherwise false * @since 5.3.0 */ public function offsetExists ($index) {} /** * Returns the value at the specified $index * @link http://php.net/manual/en/spldoublylinkedlist.offsetget.php * @param mixed $index <p> * The index with the value. * </p> * @return mixed The value at the specified <i>index</i>. * @since 5.3.0 */ public function offsetGet ($index) {} /** * Sets the value at the specified $index to $newval * @link http://php.net/manual/en/spldoublylinkedlist.offsetset.php * @param mixed $index <p> * The index being set. * </p> * @param mixed $newval <p> * The new value for the <i>index</i>. * </p> * @return void * @since 5.3.0 */ public function offsetSet ($index, $newval) {} /** * Unsets the value at the specified $index * @link http://php.net/manual/en/spldoublylinkedlist.offsetunset.php * @param mixed $index <p> * The index being unset. * </p> * @return void * @since 5.3.0 */ public function offsetUnset ($index) {} /** * Rewind iterator back to the start * @link http://php.net/manual/en/spldoublylinkedlist.rewind.php * @return void * @since 5.3.0 */ public function rewind () {} /** * Return current array entry * @link http://php.net/manual/en/spldoublylinkedlist.current.php * @return mixed The current node value. * @since 5.3.0 */ public function current () {} /** * Return current node index * @link http://php.net/manual/en/spldoublylinkedlist.key.php * @return mixed The current node index. * @since 5.3.0 */ public function key () {} /** * Move to next entry * @link http://php.net/manual/en/spldoublylinkedlist.next.php * @return void * @since 5.3.0 */ public function next () {} /** * Move to previous entry * @link http://php.net/manual/en/spldoublylinkedlist.prev.php * @return void * @since 5.3.0 */ public function prev () {} /** * Check whether the doubly linked list contains more nodes 當前指標處元素是否有效 * @link http://php.net/manual/en/spldoublylinkedlist.valid.php * @return bool true if the doubly linked list contains any more nodes, false otherwise. * @since 5.3.0 */ public function valid () {} /** * Unserializes the storage * @link http://php.net/manual/ru/spldoublylinkedlist.serialize.php * @param string $serialized The serialized string. * @return void * @since 5.4.0 */ public function unserialize($serialized) {} /** * Serializes the storage * @link http://php.net/manual/ru/spldoublylinkedlist.unserialize.php * @return string The serialized string. * @since 5.4.0 */ public function serialize () {}}

用例

<?phpheader("Content-type: text/html; charset=gb2312");$doubly=new SplDoublyLinkedList();$doubly->push(‘a‘);$doubly->push(‘b‘);$doubly->push(‘c‘);$doubly->push(‘d‘);$doubly->add(1,‘e‘);echo ‘Original:‘."\n";var_dump($doubly);echo ‘FIFO|KEEP:‘."\n";$doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP);$doubly->rewind();foreach($doubly as $key=>$value){    echo $key.‘ ‘.$value."\n";}echo ‘LIFO|KEEP:‘."\n";$doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP);$doubly->rewind();foreach($doubly as $key=>$value){    echo $key.‘ ‘.$value."\n";}echo ‘LIFO|DELETE:‘."\n";$doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_DELETE);$doubly->rewind();foreach($doubly as $key=>$value){    if($key == 1) break;    echo $key.‘ ‘.$value."\n";}echo ‘List after Delete‘."\n";var_dump($doubly);?>

 

PHP標準庫(SPL)- SplDoublyLinkedList類(雙向鏈表)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.