I need a function that splits a list of numbers into a group of evens and odds.
ID: 3689910 • Letter: I
Question
I need a function that splits a list of numbers into a group of evens and odds. I have to derive a class called intLinkedList from unorderedLinkedList(a class)
class intLinkedList: public unorderedLinkedList<int>
{
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 I need the definition of the function splitEvensOddsList, it doesnt make any new node but it takes them from the originals and puts the right nodes into even or odd list.
the program has to use intLinkedList to create a linked list of the integers and use the splitEvenOddlist to make 2 sublists to put the evens and odds on. The header is linkedList.h and unorderedLinkedList are below.
-----linkedList.h-----
----unorderedLinkedList-----
Explanation / Answer
Here is the function for you:
#include "unorderedLinkedList.cpp"
class intLinkedList: public unorderedLinkedList<int>
{
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.
*/
{
nodeType<int> *current; //pointer to traverse the list
current = this->first; //set current to point to the first
//node in the list
while (current != NULL) //search the list
if (current->info % 2 == 0) //if item is even.
evensList.insertLast(current->info);
else
oddsList.insertLast(current->info);
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.