SteppedSort

# SteppedSort - if(numbers[scan< numbers[min min = scan...

This preview shows pages 1–2. Sign up to view the full content.

//******************************************************************** // SteppedSort.java Author: Lewis and Loftus // // Solution to Programming Project 6.14 // // Performs a selection sort one step at a time. //******************************************************************** import java.awt.*; public class SteppedSort { private int[] numbers; private int index; //----------------------------------------------------------------- // Creates a new sort object to sort the values in the parameter // unsortedArray //----------------------------------------------------------------- public SteppedSort(int[] unsortedArray) { numbers = unsortedArray; index = 0; } //----------------------------------------------------------------- // Performs one step of the selection sort algorithm. //----------------------------------------------------------------- public void nextStep () { int min, temp; if (index < numbers.length-1) { min = index; for (int scan = index+1; scan < numbers.length; scan++)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (numbers[scan] < numbers[min]) min = scan; // Swap the values temp = numbers[min]; numbers[min] = numbers[index]; numbers[index] = temp; index++; } } //-----------------------------------------------------------------// Returns true if all integers in array are sorted //-----------------------------------------------------------------public boolean sortFinished() { return (index >= numbers.length-1); } //-----------------------------------------------------------------// Draws a graphical representation of the sort. //-----------------------------------------------------------------public void draw(Graphics page, int width, int height) { if (sortFinished()) page.drawString("Finished Sort", 10, height - 10); int step = width / (numbers.length + 1); for (int i=0; i<numbers.length; i++) { page.setColor(Color.blue); page.drawLine((i+1)*step, 0, (i+1)*step, numbers[i]); } } }...
View Full Document

## This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

### Page1 / 2

SteppedSort - if(numbers[scan< numbers[min min = scan...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online