©
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
(PHP 5 >= 5.3.0)
The SplDoublyLinkedList class provides the main functionalities of a doubly linked list.
$index
, mixed $newval
)$index
)$index
)$index
, mixed $newval
)$index
)$value
)$mode
)$serialized
)$value
)[#1] Maaz Rehman [2015-05-17 06:54:00]
//instantiating an object of doubly link list
$dlist=new SplDoublyLinkedList();
//a push inserts data at the end of the list
$dlist->push('hiramariam');
$dlist->push('maaz');
$dlist->push('zafar');
//while an unshift inserts an object at top of the list
$dlist->unshift(1);
$dlist->unshift(2);
$dlist->unshift(3);
//you can delete an item from the bottom of the list by using pop
$dlist->pop();
//you can delete an item from the top of the list by using shift()
$dlist->shift();
$dlist->add(3 , 2.24);
for($dlist->rewind();$dlist->valid();$dlist->next()){
echo $dlist->current()."<br/>";
}
echo "<br/>";
$dlist->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
for($dlist->rewind();$dlist->valid();$dlist->next()){
echo $dlist->current()."<br/>";;
}
[#2] Gilles A [2013-08-09 12:19:44]
FIFO and LIFO in SplDoublyLinkedList
$list = new SplDoublyLinkedList();
$list->push('a');
$list->push('b');
$list->push('c');
$list->push('d');
echo "FIFO (First In First Out) :\n";
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
for ($list->rewind(); $list->valid(); $list->next()) {
echo $list->current()."\n";
}
Result :
// FIFO (First In First Out):
// a
// b
// c
// d
echo "LIFO (Last In First Out) :\n";
$list->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
for ($list->rewind(); $list->valid(); $list->next()) {
echo $list->current()."\n";
}
Result :
// LIFO (Last In First Out):
// d
// c
// b
// a