In: Computer Science
C++:
Do not change anything in the supplied code
below that will be the Ch16_Ex5_MainProgram.cpp
except to add documentation. PLEASE DO NOT CHANGE
THE CODE JUST ADD DOCUMENTATION. Thank you. The last few have
changed the code. Appreciate you all.
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
I have added documentation for your code:
//22 34 56 4 19 2
89 90 0 14 32 88 125 56 11 43 55 -999
/* The Aim of this program is takiing the values from keyboard and
inserting into the lists..and
finally dividing the lsit into 2 halves and displaying lengths and
values of both the lists.*/
#include <iostream>
#include "unorderedLinkedList.h" //including unorderedLinkedList.h
file in this program..
using namespace std;
int main()
{
unorderedLinkedList<int> list, subList; //declaring unordered
lisked lists..
int num; //declaring a number..
cout <<
"Enter numbers ending with -999" << endl;
cin >> num;
while (num != -999)
//if num == -999 then while loop exits...
{
list.insertLast(num); //inserting the number into
unorderedLinkedList
cin >> num; //again reading th number from keyboard..
}
cout << endl;
cout <<
"List: ";
list.print(); //displaying list by print() method present inside
unorderedLinkedList.
cout << endl;
cout << "Length of the list: " << list.length()
<< endl; //diplaying length of unorderedLinkedList
list.divideMid(subList); //dividing the list into two halves..one is list, other is subList..
cout << "Lists after splitting list" << endl;
cout <<
"list: ";
list.print(); // again displaying list..
cout << endl;
cout << "Length of the list: " << list.length()
<< endl; //displaying splitted list length..
cout <<
"sublist: ";
subList.print(); //dispalying sublist... valuees stored in list...
cout << endl;
cout << "Length of subList: " << subList.length()
<< endl; //displaying length of sublist..
system("pause");
return 0;
}