Double linked list is an important linear storage structure, for each node in a doubly linked list, not only store its own information, but also save the address of the predecessor and the successor node.
The Spldoublylinkedlist class in the PHP SPL provides an operation on a double linked list.
The Spldoublylinkedlist class summary is as follows:
Spldoublylinkedlist implements iterator, arrayaccess, countable {public __construct (void) public void add (Mixed $index, mixed $newval)//The head node of the double linked list public mixed top (void)//Double linked list of the tail node public mixed bottom (void)// The number of doubly-linked table elements is public int count (void)//detect whether the double linked list is empty public bool IsEmpty (void)//current node index public mixed key (void
//Move to previous record public void prev (void)//move to next record public void Next (void)//current record public mixed present (void) Point the pointer at the beginning of the iteration with public void rewind (void)/check if the double linked list has nodes public bool valid (void)//Specify whether the index node exists public Bo Ol offsetexists (mixed $index)//Get the specified index node value public mixed Offsetget (mixed $index)//set at the specified index value public void
Offsetset (mixed $index, mixed $newval)//delete at specified index node public void Offsetunset (mixed $index)//from the tail of the double linked list pop-up elements Public mixed pop (void)//add element to the tail of a doubly-linked list (mixed $value)/serialization store public string serialize (VO ID)//deserialization public VOID unserialize (String $serialized)//Set Iteration mode public void Setiteratormode (int $mode)//Get Iteration pattern Spldoublylinkedl
Ist::it_mode_lifo (Stack style) Spldoublylinkedlist::it_mode_fifo (Queue style) public int getiteratormode (void) Double-linked list head remove element public mixed shift (void)//Double linked table header add element 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 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);