I need help on following program using c language Please sub
I need help on following program using c++ language. Please submit all files with title. Thank You.
Dividing a linked list into two sublists of almost equal sizes
a. Add the operation divideMid to the class linkedListType as follows:
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.
b. Write the definition of the function template to implement the operation divideMid. Also, write a program to test your function. Your test program should produce output similar to this:
Solution
#include <iostream>
#include \"linkedList.h\"
using namespace std;
int main()
{
linkedListType<int> lst, sblst;
linkedListType<int> tmp, otrlst;
int mo;
cout<<\"Enter numbers ending with -999\"<<endl;
cin>>mo;
while(mo != -999)
{
lst.instlast(mo);
cin>>mo;
}
tmp = lst;
cout<<endl;
cout<<\"lst: \"<<lst<<endl;
cout<<\"Length of the lst: \"<<lst.length()<<endl;
lst.divideMid(sblst);
cout<<\"Lists after splitting lst\"<<endl;
cout<<\"lst: \"<<lst<<endl;
cout<<\"Length of the lst: \"<<lst.length()<<endl;
cout<<\"sublist: \"<<sblst<<endl;;
cout<<\"Length of sblst: \"<<sblst.length()<<endl;
return 0;
}
