Introduction and use of PHP double-chain table (spldoublyshortlist), php linked list. PHP double-chain table is an important linear storage structure. for each node in a double-chain table, not only store your own information, but also the introduction and use of the PHP double-chain table (spldoublyshortlist ).
A double-chain table is an important linear storage structure. for each node in a double-chain table, it not only stores its own information, but also stores the addresses of the front-end and subsequent nodes.
The spldoublyshortlist class in php spl provides operations on double-stranded tables.
The summary of the spldoublyshortlist class is as follows:
Spldoublyshortlist implements Iterator, ArrayAccess, Countable {public _ construct (void) public void add (mixed $ index, mixed $ newval) // The header node of the double-stranded table public mixed top (void) // public mixed bottom (void) at the end of the double-link table // public int count (void) for the number of elements in the double-link table // checks whether the double-link table is empty public bool isEmpty (void) // the current node index public mixed key (void) // move to the previous record public void prev (void) // move to the next record public void next (void) // The current record public mixed current (void) // point the pointer to the beginning of the iteration public void rewind (void) // check whether the double-linked table has a node public bool valid (void) // specify whether the node at the index has the public bool offsetExists (mixed $ index) // obtain the value of the node at the specified index public mixed offsetGet (mixed $ index) // set the value of public void offsetSet (mixed $ index, mixed $ newval) at the specified index. // delete the public void offsetUnset (mixed $ index) at the specified index) // The public mixed pop (void) element pops up from the end of the double-stranded table // add the element to the end of the double-stranded table public void push (mixed $ value) // serialized storage public string serialize (void) // deserialize public void unserialize (string $ serialized) // sets the public void setIteratorMode (int $ mode) of the iteration mode) // Obtain the iterative mode spldoublyshortlist: IT_MODE_LIFO (Stack style) spldoublyshortlist: IT_MODE_FIFO (Queue style) public int getIteratorMode (void) // remove the public mixed shift (void) element from the header of the double-stranded table // add the public void unshift (mixed $ value) element to the header of the double-stranded table )}
Easy to use
$list = new SplDoublyLinkedList();$list->push('a');$list->push('b');$list->push('c'); $list->unshift('top');$list->shift(); print_r(array( 'pop' => $list->pop(), 'count' => $list->count(), 'isEmpty' => $list->isEmpty(), 'bottom' => $list->bottom(), 'top' => $list->top())); $list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);print_r($list->getIteratorMode()); for($list->rewind(); $list->valid(); $list->next()) { echo $list->current().PHP_EOL;} print_r($a = $list->serialize());//print_r($list->unserialize($a)); $list->offsetSet(0,'new one');$list->offsetUnset(0);print_r(array( 'offsetExists' => $list->offsetExists(4), 'offsetGet' => $list->offsetGet(0), ));print_r($list);
Http://www.bkjia.com/PHPjc/998571.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/998571.htmlTechArticlePHP double-chain table (SplDoublyLinkedList) introduction and use examples, php linked list double-chain table is an important linear storage structure, for each node in the double-chain table, not only store their own information...