May 2017
Intermediate to advanced
340 pages
8h 16m
English
Building a circular linked list is not at as hard as it sounds from the name. So far, we have seen that adding a new node at the end is pretty simple; we set the next reference of the last node to NULL. In a circular linked list, the last node's next reference will actually point to the first node, thereby creating a circular list. Let's write a simple circular linked list where the nodes will be inserted at the end of the list:
class CircularLinkedList { private $_firstNode = NULL; private $_totalNode = 0; public function insertAtEnd(string $data = NULL) { $newNode = new ListNode($data); if ($this->_firstNode === NULL) { $this->_firstNode = &$newNode; } else { $currentNode = $this->_firstNode; while ...Read now
Unlock full access