0% found this document useful (0 votes)
7 views1 page

Lesson 34 - C++ Mergesort

Uploaded by

kdudeteam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Lesson 34 - C++ Mergesort

Uploaded by

kdudeteam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

LAB EXERCISE

MERGELIST

Assignment:

1. The data file to be used in this lab is (file20.txt).

2. Building the initial linked list from (file20.txt) should follow this logic. As each new piece
of data (Id/Inv pair) comes off the data file, it is placed at the beginning of the list.
Therefore, the first values read from the data file will end up last in the list. We do not want
to have two external pointers (first/last) to the linked list as used in Lesson 33. Instead, we
want only one pointer to the first node in the list.

3. The recursive merge sort algorithm will need the supporting algorithms of splitting and
merging lists.

4. The parameter list of the reverse function should be as follows:

void reverseList (listPtr &root);


// listPtr would be a typedef for something like listNode *

5. Your program should consist of this sequence of scripted events:

Load the data file and build the initial list


Print the linked list - it is unordered
Recursively merge sort the list
Print the linked list - it is now sorted
Reverse the linked list
Print the linked list - it is now in descending order

Instructions:

1. Turn in your source code and a run output.

APCS - C++, Lesson 34 ©1998, ICT L.A.34.1

You might also like