Question: QUESTION: You are given a function dividelist() within a header file. Fill certain parts left blank in the code snippet in order to complete the

QUESTION: You are given a function dividelist() within a header file. Fill certain parts left blank in the code snippet in order to complete the list division for the merge sort algorithm to work. After getting successfully divided sublists, the next step will be to apply the merging of those lists. Please note that most of the sorting is done during the merging process of these sublists for the merge sort. Elements of the sublists are compared with each other and the nodes with smaller data are adjusted accordingly during this process. This process continues for all of the remaining elements in sublists.

We should write the missing codes where it says "COMMENT"

template

void unorderedLinkedList::divideList(nodeType* first1,nodeType* &first2)

{

nodeType* middle;

nodeType* current;

/* Add code snippet right here to check wheter the list is empty COMMENT

or if the list has only one node or not,

*/

else

{

middle = first1;

current = first1->link;

if (current != NULL) //list has more than two nodes

current = current->link;

while (current != NULL)

{

/* set the middle & current node pointers correctly*/COMMENT

} //end while

first2 = middle->link; //first2 points to the first

//node of the second sublist

//****set the link of the last node here COMMENT

//of the first sublist to NULL

} //end else

} //end divideList

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!