diff options
-rw-r--r-- | engines/titanic/true_talk/tt_node.cpp | 17 | ||||
-rw-r--r-- | engines/titanic/true_talk/tt_node.h | 11 |
2 files changed, 28 insertions, 0 deletions
diff --git a/engines/titanic/true_talk/tt_node.cpp b/engines/titanic/true_talk/tt_node.cpp index 22695ad379..c72dfd3e51 100644 --- a/engines/titanic/true_talk/tt_node.cpp +++ b/engines/titanic/true_talk/tt_node.cpp @@ -38,6 +38,12 @@ void TTnode::addNode(TTnode *newNode) { newNode->_priorP = this; } +void TTnode::addToHead(TTnode *newNode) { + TTnode *head = getHead(); + head->_priorP = newNode; + newNode->_nextP = head; +} + void TTnode::detach() { if (_priorP) _priorP->_nextP = _nextP; @@ -58,6 +64,17 @@ void TTnode::deleteSiblings() { } } +TTnode *TTnode::getHead() { + if (_priorP == nullptr) + return this; + + TTnode *node = _priorP; + while (node->_priorP) + node = node->_priorP; + + return node; +} + TTnode *TTnode::getTail() { if (_nextP == nullptr) return this; diff --git a/engines/titanic/true_talk/tt_node.h b/engines/titanic/true_talk/tt_node.h index f8d1bc6766..8faebae18f 100644 --- a/engines/titanic/true_talk/tt_node.h +++ b/engines/titanic/true_talk/tt_node.h @@ -39,6 +39,12 @@ public: void addNode(TTnode *newNode); /** + * Adds a new node at the beginning of the linked list + */ + void addToHead(TTnode *newNode); + + + /** * Detaches a node from any predecessor and/or successor */ void detach(); @@ -49,6 +55,11 @@ public: void deleteSiblings(); /** + * Returns the first node at the beginning of a linked list of nodes + */ + TTnode *getHead(); + + /** * Returns the final node at the end of the linked list of nodes */ TTnode *getTail(); |