Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(DIVIDING A LINKED LIST INTO TWO SUBLISTS OF ALMSOT EQUAL SIZES) a. Add the operation divideMid to the class linkedListType as follows: void divideMid(linkedListType &sublist);

(DIVIDING A LINKED LIST INTO TWO SUBLISTS OF ALMSOT EQUAL SIZES)

a. Add the operation divideMid to the class linkedListType as follows: void divideMid(linkedListType &sublist); //This operation divides the given list into tow 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 myList; unorderedLinkedList 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 2 sublists: myList points to the list with the elements 34 65n27, 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.

//use these file names

linkedList.h unorderedLinkedList.h

// 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 #include "unorderedLinkedList.h" using namespace std; int main() { unorderedLinkedList 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; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

Students also viewed these Databases questions