Do not change anything in the supplied Ch16Ex5MainProgramcpp

Do not change anything in the supplied Ch16_Ex5_MainProgram.cpp except to add documentation and your name.

Please use the file names listed below since your file will have the following components:

Ch16_Ex5_MainProgram.cpp - given file


//22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999

#include <iostream>
#include \"unorderedLinkedList.h\"

using namespace std;

int main()
{
unorderedLinkedList<int> list, subList;

int num;                                                                                                                       

            cout << \"Enter numbers ending with -999\" << endl;                                                                                                                     
cin >> num;                                                                                                     

            while (num != -999)                                                                                          
{
list.insertLast(num);                                                                  
cin >> num;                                                                                                     
}

            cout << endl;                                                                                                   

            cout << \"List: \";                                                
list.print();                                                                                                        
cout << endl;                                                                                                               
cout << \"Length of the list: \" << list.length() << endl;                                                                                                      

            list.divideMid(subList);

            cout << \"Lists after splitting list\" << endl;

            cout << \"list: \";
list.print();                                                                                                        
cout << endl;                                                                                                               
cout << \"Length of the list: \" << list.length() << endl;                  

            cout << \"sublist: \";
subList.print();                                                                                                  
cout << endl;                                                                                                               
cout << \"Length of subList: \" << subList.length() << endl;
system(\"pause\");
return 0;                                                          
}

linkedList.h
unorderedLinkedList.h

Dividing a linked list into two sublists of almost equal sizes:

Add the operation divideMid to the class linkedListType as follows:

void divideMid(linkedListType &sublist);
//This operation divides the given list into two sublists
//of (almost) equal sizes.
//Postcondition: first points to the first node and last
//          points to the last node of the first
//          sublist.
//          sublist.first points to the first node
//          and sublist.last points to the last node
//          of the second sublist.
Consider the following statements:

unorderedLinkedList <int> myList;
unorderedLinkedList <int> subList;

Suppose myList points to the list with elements 34 65 27 89 12 (in this order). The statement:

myList.divideMid(subList);

divides myList into two sublists: myList points to the list with the elements 34 65 27, and subList points to the sublist with the elements 89 12.

Write the definition of the function template to implement the operation divideMid. Also, write a program to test your function.

Programming Language is C++

Solution

#include <iostream>
#include \"unorderedLinkedList.h\"

using namespace std;

int main()
{
unorderedLinkedList<int> list, subList;

int num;                                                                                                                       

            cout << \"Enter numbers ending with -999\" << endl;                                                                                                                     
cin >> num;                                                                                                     

            while (num != -999)                                                                                          
{
list.insertLast(num);                                                                  
cin >> num;                                                                                                     
}

            cout << endl;                                                                                                   

            cout << \"List: \";                                                
list.print();                                                                                                        
cout << endl;                                                                                                               
cout << \"Length of the list: \" << list.length() << endl;                                                                                                      

            list.divideMid(subList);

            cout << \"Lists after splitting list\" << endl;

            cout << \"list: \";
list.print();                                                                                                        
cout << endl;                                                                                                               
cout << \"Length of the list: \" << list.length() << endl;                  

            cout << \"sublist: \";
subList.print();                                                                                                  
cout << endl;                                                                                                               
cout << \"Length of subList: \" << subList.length() << endl;
system(\"pause\");
return 0;                                                          
}

Do not change anything in the supplied Ch16_Ex5_MainProgram.cpp except to add documentation and your name. Please use the file names listed below since your fil
Do not change anything in the supplied Ch16_Ex5_MainProgram.cpp except to add documentation and your name. Please use the file names listed below since your fil
Do not change anything in the supplied Ch16_Ex5_MainProgram.cpp except to add documentation and your name. Please use the file names listed below since your fil

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site