Help with making a header file or intLinkedList and a test program to use class
ID: 3689952 • Letter: H
Question
Help with making a header file or intLinkedList and a test program to use class splitEvensOddsList
Heres what i have so far:
Function definition for splitEvensOddsList
------evenOdds
#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);
}
};
I have no clue on how to make IntLinkedList.h
------- unorderedLinkedList----
Linked List Proiect 3 Attached Files linkedList.h (11.273 KB) Split a list into evens and odds a. Derive the class intLinkedList from the class unorderedLinkedList as follows class intLinkedList: public unorderedLinkedList unorderedLinkedList.h (5.854 KB) 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 node, 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 b. Write a program that uses class intLinkedList to create a linked list of integers and then uses the function splitEvens0ddsLst to split the list into two sublists. The header files linke dList.h and unorderedLinkedList.hare 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 urn i .The header file for your derived class intLinkedList.h . Your test programExplanation / Answer
intLinkedList.h
#ifndef H_IntLinkedList
#define H_IntLinkedList
#include "unorderedLinkedList.h"
using namespace std;
class intLinkedList: public unorderedLinkedList<int>
{
public:
void splitEvensOddsList(intLinkedList &evensList,intLinkedList &oddsList);
};
void intLinkedList::splitEvensOddsList(intLinkedList &evensList,intLinkedList &oddsList)
{
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);
current=current->link;
}
}
test.cpp
#include <iostream>
#include "intLinkedList.h"
using namespace std;
int main()
{
intLinkedList list;
for(int i=1;i<10;++i)
{
list.insertLast(i);
}
intLinkedList evens;
intLinkedList odds;
list.splitEvensOddsList(evens,odds);
linkedListIterator<int> iter=evens.begin();
while(iter!=NULL)
{
cout<<"evens list"<<endl;
cout<<*iter<<endl;
++iter;
}
iter=odds.begin();
while(iter!=NULL)
{
cout<<"odds list"<<endl;
cout<<*iter<<endl;
++iter;
}
}
sample output:
evens list
2
evens list
4
evens list
6
evens list
8
odds list
1
odds list
3
odds list
5
odds list
7
odds list
9
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.