Sort - a[pass] = temp; } } public static void main(String...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
public class Sort { public static void selectionSort(double[] a) { for (int pass = 0; pass < a.length - 1; pass++) { int smallestindex = pass; for (int index = pass+1; index < a.length; index++) { if(a[index] < a[smallestindex]) { smallestindex = index; } } double temp = a[smallestindex]; a[smallestindex] = a[pass];
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a[pass] = temp; } } public static void main(String args) { //double array = new double[10]; //array[0] = 4.6; double array = { 9.4, 4.7, 8.9, 2.4, 8.4 }; selectionSort(array); for (int i = 0; i &lt; array.length; i++) { System.out.println(array[i]); } } }...
View Full Document

Ask a homework question - tutors are online