Program 4: Sorting Visualization

Due Date

This assignment is due at the beginning of your lab period on Thursday, April 8th.

Partners

You may work with at most one other person on this assignment. Your partner must be in the same lab section as yourself. Please review the class collaboration policy (available off of the main CS 221 page) so that you know what is and what isn't allowed.

Purpose

The purpose of this program is to introduce you to sorting and to show you how a visualization tool can be helpful for better understanding how an algorithm works.

B Level Assignment

User Input Requirements

In a GUI, the user should be able to select

  1. The number of integers to sort. This should be a number between 1 and 100.
  2. The range of the integers to sort. The lower bound of the range must >= 1 and the upper bound must be <= 1000.
  3. The sorting method to use. For the B level assignment, the only choice that the user gets is InsertionSort. When this choice is selected, an appropriately sized array of random integers in the requested range should be generated and sorted into ascending order using the insertion sort technique.

Graphical Display Requirements

Suppose that the user wants to sort n integers. The graphical display should be updated by the user n-1 times during the course of the sorting. (Perhaps the user will press a Continue button n-1 times.) The first display should show the initial array graphically. To display the contents of the array graphically, use rectangles whose height is proportional to the size of the integers that they represent. The rectangles should be displayed from left to right such that the leftmost rectangle represents the integer in the leftmost position of the array and the rightmost rectangle represents the integer in the rightmost position of the array. The second display should show the array after one insertion pass has been made. The third display should show the array after two insertion passes have been made. This should continue until the nth display shows the array after n-1 insertion passes have been made. At this point, the array will be sorted.

BlueJ Terminal Window Requirements

At the start of the run, the initial array should be printed to the BlueJ terminal window. At the end of the run, the sorted array should be printed to the BlueJ terminal window.

A Level Assignment

Add QuickSort as another sorting method.

What to Submit

  1. A disk with your code on it. This is important as your program will be tested in lab on Thursday, April 8th.
  2. A printout of the source code that you write.
  3. A printout of the output that your program sends to the BlueJ terminal output window.

Grading

Valid XHTML 1.0!