CS 1711 Recitation Exercise 9:
Animation of Sorting and Other Array Algorithms

Objectives:

Prior to the recitation:

Hand-in Requirements:

(All hand-ins should be stapled in the upper left corner to form a single packet. Write your name, course and section number on the front.)

Setup:

  •  Project/Package Name:  arraydisplaypkg
  • New Main Class: ArrayDisplayTest
  • New Class: ArrayDisplay
  • Save All

  • Save ArrayDisplay.java in your src/arraydisplaypkg directory

    Overview:

    In this recitation exercise, you will use a graphical representation to show the progress of different array algorithms such as finding the maximum element or sorting an array with the selection sort. A common method of animating array algorithms is to display the array as a bar graph, with the height of the bar corresponding to each element being proportional to the size of the element. The animation changes the colors of the bars to emphasize aspects of the algorithm. For example, as a sort algorithm moves elements in the array, the bar graph is redisplayed with the elements in their new positions. The bars are usually displayed in some default color (say red) and the color is changed (say to blue) when a bar reaches its final position. The left image below shows an array with 30 elements. The image on the right shows the same array with the color of element number 10 set to blue.

    You will use the prewritten class ArrayDisplay to do the animation of your algorithms. This class contains a randomly generated array of double that it automatically displays in a window as a bar graph. You can change the colors of the individual bars and redisplay. The public methods of ArrayDisplay are:

    In part I of the recitation you will experiment with the methods of ArrayDisplay. In part II you will animate a relatively simple algorithm -- finding the maximum value of an element in an array. In part III you will animate the selection sort.

    Details:

    Setup:

  •  Project/Package Name:  extremestestpkg
  • New Main Class: ExtremesTest
  • New Class: ArrayDisplay
  • New Class: Extremes
  • Save All

  • Save ArrayDisplay.java  and Extremes.java in your src/extremestestpkg directory

    Setup:

    Study Questions:


    Last revision: October 27, 2001 at 9:38 am