Question: Class declaration for the Doubly linked implementation of the List ADT // //-------------------------------------------------------------------- #ifndef LISTLINKED_H #define LISTLINKED_H #include using namespace std; template class ListNode {

Class declaration for the Doubly linked implementation of the List ADT // //-------------------------------------------------------------------- #ifndef LISTLINKED_H #define LISTLINKED_H #include using namespace std; template class ListNode { // doubly linked list node public: ListNode(const DataType& nodeData, ListNode* nextPtr, ListNode* prevPtr); DataType dataItem; ListNode* next; ListNode* prev; }; template class List { // a list implemented using doubly linked nodes public: List(); List(const List& other); // copy constructor List& operator=(const List& other); // assignment operator ~List(); void insert(const DataType& newDataItem); // insert an item after cursor void remove(); // remove the cursor node, and move the cursor to the next node. If the removed node is the last node, move the cursor to the beginning of the list void replace(const DataType& newDataItem); // replace the cursor node value void clear(); // clear the list, remove all nodes bool isEmpty() const; bool isFull() const; void gotoBeginning(); // move cursor to the beginning of the list void gotoEnd(); // move cursor to the end of the list bool gotoNext(); // move cursor to the next node, return false if no next node is available bool gotoPrior(); // move cursor to the prior node, return false if no prior node is available DataType getCursor() const; // return the value of the cursor node void moveToBeginning (); // move the cursor node to the beginning of the list void insertBefore(const DataType& newDataItem); // insert a new item before the cursor void print() const; // print the list, mark the cursor node private: // Do not change them for this homework ListNode* head; ListNode* cursor; }; #endif *** SOLUTION: Linked list cpp file implementation of the List ADT *** // c // //-------------------------------------------------------------------- #ifndef LISTLINKED_CPP #define LISTLINKED_CPP using namespace std; #include // For showStructure #include "ListLinked.h" template ListNode::ListNode(const DataType& nodeData, ListNode* nextPtr, ListNode* prevPtr) // Creates a list node containing item elem and next pointer // nextPtr. : dataItem(nodeData), next(nextPtr), prev(prevPtr) { } //-------------------------------------------------------------------- template List::List() // Creates an empty list. : head(0), cursor(0) { } //-------------------------------------------------------------------- template List::List(const List& other) : head(0), cursor(0) // Copy constructor. Creates a list which is equivalent in content // to the "other" list. { operator=(other); } //-------------------------------------------------------------------- template List& List::operator=(const List& other) // Overloaded assignment operator. Reinitializes the list to be // equivalent in content to the "other" list. // Note: we include self-assignment protection by checking whether // "this" object is identical to the "other" object. { if( this != &other ) { clear(); ListNode *otherPtr = other.head; ListNode *holdCursor = NULL; while( otherPtr != NULL ) { insert(otherPtr->dataItem); if(otherPtr == other.cursor) { holdCursor = cursor; } otherPtr = otherPtr->next; } cursor = holdCursor; } return *this; } //-------------------------------------------------------------------- template List::~List() // Destructor. Frees the memory used by a list. { clear(); }

Doubly Linked List is a data structure that holds a list of items with double links: previous and next. In this homework, you need to implement all functions in the defined ListLinked class (prototype is provided by the instructor). Please download the header file (ListLinked.h) from ecourses, read the comments and complete them using C++. You need to implement all of the ListLinked ADT functions in ListLinked.cpp file, and test them in main.cpp.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!