PHP doubly linked list (spldoublylinkedlist) Introduction and usage examples, PHP linked list
Doubly linked list is an important linear storage structure, for each node in a doubly linked list, not only to store their own information, but also to save the predecessor and the successor node address.
The Spldoublylinkedlist class in PHP SPL provides the operation of a doubly linked list.
The Spldoublylinkedlist class is summarized as follows:
Spldoublylinkedlist implements Iterator, arrayaccess, countable {public __construct (void) public void Add (mi Xed $index, mixed $newval)//The head node of the doubly-linked list public mixed top (void)//The tail node of the doubly linked list public mixed bottom (void)//number of doubly-linked table elements public int count (void)//detect double-linked list is empty public bool IsEmpty (void)//current node index public mixed key (void)//move to previous record Pu Blic void prev (void)//move to the next record public void Next (void)//The current record public mixed present (void)//pointer to public at the beginning of the iteration void Rewind (void)//Check whether a doubly linked list has a node public bool valid (void)//Specify whether the node at index has a public bool offsetexists (mixed $inde x)//Gets the node value at the specified index public mixed offsetget (mixed $index)//Set the value at the specified index public void Offsetset (mixed $index, mixed $newval)//delete the specified index node public void Offsetunset (mixed $index)//eject element from the tail of the doubly linked list public mixed pop (void)//add element to double chain The end of the table, public void push (mixed $value)//serialization store public string serialize (void)//deserialization public void unserialize (str ing $serialized)//SetIteration mode public void Setiteratormode (int $mode)//Get Iteration pattern Spldoublylinkedlist::it_mode_lifo (Stack style) Spldoublylinkedli St::it_mode_fifo (Queue style) public int getiteratormode (void)//The head of the doubly linked list removes the element public mixed shift (void)//double-linked list header Tim CAD public void Unshift (mixed $value)}
It's easy to use.
$list = new Spldoublylinkedlist (), $list->push (' a '), $list->push (' B '); $list->push (' C '); $list->unshift (' top '); $list->shift (); Print_r ( ' pop ' = $list->pop (), ' count ' = = $list->count (), ' isEmpty ' + $list IsEmpty (), ' bottom ' = $list->bottom (), ' top ' = $list->top ())); $list->setiteratormode (Spldoublylinkedlist::it_mode_fifo);p Rint_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);p Rint_r (Array ( ' offsetexists ' = $list Offsetexists (4), ' offsetget ' = $list->offsetget (0),));p Rint_r ($list);
http://www.bkjia.com/PHPjc/998571.html www.bkjia.com true http://www.bkjia.com/PHPjc/998571.html techarticle PHP doubly linked list (spldoublylinkedlist) Introduction and use of examples, the PHP linked list is an important linear storage structure, for each node in a doubly linked list, not only to store their own information ...