C++ Linked List

C++ Linked List

Dividing a linked list into two sublists of almost equal sizes

a. Add the operation divideMid to the class linkedListType as follows:

void divideMid(linkedListType<Type> &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.

b. Write the definition of the function template to implement the operation divideMid. Also, write a program to test your function. The header files linkedList.h and unorderedLinkedList.h are supplied. Your test program should produce output similar to this:

Enter numbers ending with -999 22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999 List: 22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 Length of the list: 17 Lists after splitting list list: 22 34 56 4 19 2 89 90 0 Length of the list: 9 sublist: 14 32 88 125 56 11 43 55 Length of subList: 8

Need linkedList.h with modifications main.cpp