Question
C++ please put everthing after you answer it, thanks Complete the stub file for the DoublyLinkedList implementation. Please note: Any changes to the NodeType struct,
C++ please put everthing after you answer it, thanks
Complete the stub file for the DoublyLinkedList implementation.
Please note: Any changes to the NodeType struct, not using the NodeType struct, or changing from template Type to using a specific data type will all be cause for deductions.
You are required to implement the methods:
insertFirst
insertLast
insertNode - (insert an item at a given index)
deleteNode - (remove a specific item)
The stub file contains the basic class format to implement the virtual methods from ListType. You should only need to complete the code for these four functions. Your code must maintain (or add) the node connections both forward and backward. In the double link list class these are called next and prev.
Your code must also maintain the count variable.
You may create any helper functions you like but they should contain comments explaining why they are helpfulecessary. Hint: You may find creating a private getNode(int index) function -- which returns a link to any internal node -- helpful.
\} template Type ListType: : back( ) const \{ assert(tail != NULL); //confirm tail exists return tail->data; //return the data of the tail node \} template void ListType>: :copyList (const ListType> \& otherList) \{ NodeType *newNode; //pointer to create a node NodeType current; //pointer to traverse the list if (head != NULL) //if the list is nonempty, make it empty destroyList(); if (otherList. head == NULL) //otherList is empty \{ head = NULL; tail = NULL; count =0; \} else \{ current = otherList. head; // current points to the count = otherList . count; // list to be copied //copy the head node head = new NodeType ; / / create the node head->data = current > data; // copy the data head->next = NULL; // set the link field of tail = head; // the node to NULL // the next node //copy the remaining list while (current != NULL) \{ newNode = new NodeType ;// create a node newNode > data = current > data; // copy the data newNode->next = NULL; // set the link of // newNode to NULL tail->next = newNode; //attach newNode after tail tail = newNode; // make tail point to //the actual tail node current = current > next; 1/ make current point //to the next node \}/ /end while \}/lend else \}//end copylistStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started