Lab 2: Linked Lists

The goal of this lab is to practice using linked lists.

1. Introduction and set up

In class last Friday we wrote a selection sort method for linked lists. You can copy this, as well as a node class and a comparison-counting driver, from the course home directory. (First, make a directory for this lab.)

cd cs245
mkdir lab2
cd lab2
cp /cslab/class/cs245/lab2/* .

Now you will practice using linked lists by writing methods that implement insertion, bubble, and merge sorts.

2. Implementing sorts

Each group should pick one algorithm to implement. We will all share code that we write in Part I for use in Part II. For your sorting algorithm, open a new file and writing a class with a static sort() method, using SelectionList.java as a model. Since these methods must return both the sorted list and the number of comparisons, its return type is IntListPair, a minimal class which holds an int and a list.

Use the driver SortList to test your sorting algorithms. It works essentially the same as SortArray.

3. Sharing your code

Now, copy the file that you wrote to a directory that everyone has access to, /cslab/pubshare.

cp SomeFile.java /cslab/pubshare

Thomas VanDrunen
Last modified: Wed Sep 12 10:34:19 CDT 2007