The goal of this assignment is to practice writing algorithms on linked lists.
In this project you will write one more sorting algorithm for lists: merge sort. Refer again to project 3 to review how merge sort works in general.
Copy the files from the subdirectory for this project. These files are a revision of the ones you used in lab 12.
cp /homeemp/tvandrun/pub/235/proj7/* .
As in the lab, the driver and a big part of the list class is already provided for you.
Also, the basic merge sort algorithm is given for you in
the method sort()
in class ListMerge
.
Your task is to write the following methods that sort()
needs:
half()
, a method in List
This method does two things: It remove the last half of nodes from the list
on which it is called and it returns those removed nodes as their
own list.
For example, if it were called on the list
List
object)
merge()
, a static method in ListMerge
.
Notice that this is not called on a list, and since it is not part of the
List
class, it does not have access to the private members
(i.e., head
) of any list.
Consequently, merge()
will almost certainly need
removeHead()
and addToBack()
.
You can implement these exactly as you did for lab 12.
It is possible that you will write merge
in such a way
that you wish List
to have some extra operations;
feel free to add more operations to List
as you see fit.
Do the normal turn-in procedure: Script file, cat the files you changed, compile, run a few times.
> a2ps -P sp (the name of the script file)
Then turn in the hard copy by 5:00, Tue, Apr 3.