Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

\} 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 copylist

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions