Using PHP SplDoublyLinkedList
The PHP Standard PHP Library (SPL) has an implementation of a doubly linked list, which is known as SplDoublyLinkedList
. If we are using the built-in class, we do not need to implement the doubly linked list ourselves. The doubly linked list implementation actually works as a stack and queue as well. The PHP implementation of the doubly linked list has lots of additional functionalities. Here are some of the common features of SplDoublyLinkedList
:
Method | Description |
| Adds a new node in a specified index |
| Peeks a node from beginning of the list |
| Returns the size of the list |
| Returns the current node |
| Returns the mode of iteration |
| Sets the mode of iteration. For example, LIFO, FIFO, and so on |
| Returns the current node index |
| Moves to the next node |
| Pops a node from the end of the list |
| Moves to the previous node |
| Adds a new node at the end of the list |
| Rewinds the iterator back to the top |
| Shifts a node from... |