SplDoublyLinkedList 链表
最后更新于:2022-04-02 02:26:00
[TOC]
## 实例
```
push('hiramariam');
$dlist->push('maaz');
$dlist->push('zafar');
/* the list contains
hiramariam
maaz
zafar
*/
$dlist->unshift(1);
$dlist->unshift(2);
$dlist->unshift(3);
/* the list now contains
3
2
1
hiramariam
maaz
zafar
*/
$dlist->pop();
/* the list now contains
3
2
1
hiramariam
maaz
*/
// 从头部删除
$dlist->shift();
/* the list now contains
2
1
hiramariam
maaz
*/
// 根据 index 替换,不存在抛异常
// add($index, $newval)
$dlist->add(3 , 2.24);
for($dlist->rewind();$dlist->valid();$dlist->next()){
echo $dlist->current()."\n";
}
echo "\n";
// 设置先进先出
$dlist->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
for($dlist->rewind();$dlist->valid();$dlist->next()){
echo $dlist->current()."\n";
}
```
';