Goals for this assignment are to:
Read Chapter 7 and 8.
We will go over the following in class on Wed, Oct 24. They will not be collected but please be ready to discuss them. Try to complete as much as you can.
Download and unzip the project SortAnimThreaded.
This project contains a program that can animate a number of different sorts. The version you have only implements insertion sort. Run the code to see what it does. In this lab, you are to implement bubble and selection sorts. You will implement the other sorts in later labs. The program also computes the number of comparisons and swaps that each sort uses.
The items to be sorted are integers from zero up to size. The integers are
stored in the variable called list
which is of type ArrayList<Integer>
. Take a look at
how insertion sort is implemented. Your task is to implement the run()
method contained in the
BubbleSort and SelectionSort classes. The run() method is where the sorting is done.
The animation is done via the pause()
method which redraws the screen and
pauses the process so that you can see what is happening. The pause()
method
should be called each time items in the list are compared (note, you get different delays if
you pause each time items are swapped - which one makes more sense to use?).
The code contains variables called swaps
and comparisons
. Modify
your code so that these are incremented when either a swap or a comparison is performed.
The last lines given in sort()
prints out the sorted list
and the values of swaps
and comparisons
.
Questions
No need to turn these in. We will discuss them in class.
By no later than class on Wednesday, Oct 24, you should do the following:
By no later than class on Monday, Oct 29, you should do the following:
Demonstrate the SortAnimThreaded code no later than Thursday,Nov 1.