Question: This is C++ Please sumbit all files of code with their names Split a list into evens and odds without creating or deleting nodes. Derive

This is C++ Please sumbit all files of code with their names

Split a list into evens and odds without creating or deleting nodes. Derive the class intLinkedList from the class unorderedLinkedList as follows: class intLinkedList: public unorderedLinkedList

{ public: void splitEvensOddsList(intLinkedList &evensList, intLinkedList &oddsList); // Function to rearrange the nodes of the linked list so // that evensList consists of even integers and oddsList // consists of odd integers. // Postcondition: evensList consists of even integers. // oddsList consists of odd integers. // The original list is empty. // }; Also write the definition of the function splitEvensOddsList. Note that this function does not create any new nodes, it only rearranges the nodes of the original list so that nodes with even integers are in evensList and nodes with odd integers are in oddsList. Write a program that uses class intLinkedList to create a linked list of integers and then uses the function splitEvensOddsList to split the list into two sublists. The header files linkedList.h and unorderedLinkedList.h are supplied.

Your test program should produce output similar to this:

Enter integers ending with -999 34 62 21 10 15 90 66 53 7 120 88 36 90 11 17 24 10 -999 list: 34 62 21 10 15 90 66 53 7 120 88 36 90 11 17 24 10 evensList: 34 62 10 90 66 120 88 36 90 24 10 oddsList: 21 15 53 7 11 17

Your test program should use iterators to print the lists rather than the class print functions.

Turn in your all three of your template files, your test program, and screen shots of your testing.

************************************************************************************

#ifndef H_UnorderedLinkedList #define H_UnorderedLinkedList #include "linkedList.h" using namespace std; template  class unorderedLinkedList: public linkedListType { public: bool search(const Type& searchItem) const; //Function to determine whether searchItem is in the list. //Postcondition: Returns true if searchItem is in the // list, otherwise the value false is // returned. void insertFirst(const Type& newItem); //Function to insert newItem at the beginning of the list. //Postcondition: first points to the new list, newItem is // inserted at the beginning of the list, // last points to the last node in the // list, and count is incremented by 1. void insertLast(const Type& newItem); //Function to insert newItem at the end of the list. //Postcondition: first points to the new list, newItem // is inserted at the end of the list, // last points to the last node in the // list, and count is incremented by 1. void deleteNode(const Type& deleteItem); //Function to delete deleteItem from the list. //Postcondition: If found, the node containing // deleteItem is deleted from the list. // first points to the first node, last // points to the last node of the updated // list, and count is decremented by 1. }; template  bool unorderedLinkedList:: search(const Type& searchItem) const { nodeType *current; //pointer to traverse the list bool found = false; current = this->first; //set current to point to the first //node in the list while (current != nullptr && !found) //search the list if (current->info == searchItem) //searchItem is found found = true; else current = current->link; //make current point to //the next node return found; }//end search template  void unorderedLinkedList::insertFirst(const Type& newItem) { nodeType *newNode; //pointer to create the new node newNode = new nodeType; //create the new node newNode->info = newItem; //store the new item in the node newNode->link = this->first; //insert newNode before first this->first = newNode; //make first point to the //actual first node this->count++; //increment count if (this->last == nullptr) //if the list was empty, newNode is also //the last node in the list this->last = newNode; }//end insertFirst template  void unorderedLinkedList::insertLast(const Type& newItem) { nodeType *newNode; //pointer to create the new node newNode = new nodeType; //create the new node newNode->info = newItem; //store the new item in the node newNode->link = nullptr; //set the link field of newNode //to nullptr if (this->first == nullptr) //if the list is empty, newNode is //both the first and last node { this->first = newNode; this->last = newNode; this->count++; //increment count } else //the list is not empty, insert newNode after last { this->last->link = newNode; //insert newNode after last this->last = newNode; //make last point to the actual //last node in the list this->count++; //increment count } }//end insertLast template  void unorderedLinkedList::deleteNode(const Type& deleteItem) { nodeType *current; //pointer to traverse the list nodeType *trailCurrent; //pointer just before current bool found; if (this->first == nullptr) //Case 1; the list is empty. cout << "Cannot delete from an empty list." << endl; else { if (this->first->info == deleteItem) //Case 2 { current = this->first; this->first = this->first->link; this->count--; if (this->first == nullptr) //the list has only one node this->last = nullptr; delete current; } else //search the list for the node with the given info { found = false; trailCurrent = this->first; //set trailCurrent to point //to the first node current = this->first->link; //set current to point to //the second node while (current != nullptr && !found) { if (current->info != deleteItem) { trailCurrent = current; current = current-> link; } else found = true; }//end while if (found) //Case 3; if found, delete the node { trailCurrent->link = current->link; this->count--; if (this->last == current) //node to be deleted //was the last node this->last = trailCurrent; //update the value //of last delete current; //delete the node from the list } else cout << "The item to be deleted is not in " << "the list." << endl; }//end else }//end else }//end deleteNode #endif

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!