From 4d3ca910b7ba193eb118852380c2727747ed9eb6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 20 May 2016 07:18:39 -0400 Subject: TITANIC: Added TTnode methods --- engines/titanic/true_talk/tt_node.cpp | 17 +++++++++++++++++ engines/titanic/true_talk/tt_node.h | 11 +++++++++++ 2 files changed, 28 insertions(+) (limited to 'engines') 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 @@ -38,6 +38,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 */ @@ -48,6 +54,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 */ -- cgit v1.2.3