SteppedSort - if (numbers[scan] < numbers[min])...

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

View Full Document Right Arrow Icon
//******************************************************************** // 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++)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (numbers[scan] &lt; 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 &gt;= numbers.length-1); } //-----------------------------------------------------------------// Draws a graphical representation of the sort. //-----------------------------------------------------------------public void draw(Graphics page, int width, int height) { if (sortFinished()) page.drawString(&quot;Finished Sort&quot;, 10, height - 10); int step = width / (numbers.length + 1); for (int i=0; i&lt;numbers.length; i++) { page.setColor(Color.blue); page.drawLine((i+1)*step, 0, (i+1)*step, numbers[i]); } } }...
View Full Document

Page1 / 2

SteppedSort - if (numbers[scan] &amp;amp;lt; numbers[min])...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online