import java.util.*; import java.io.*; public class SelectionSort { public static void main(String[] args) throws FileNotFoundException { int size; Scanner input = new Scanner(new File("sort.data")); size = input.nextInt(); System.out.println("Reading file of size " + size); int[] x = new int[size]; for (int i=0; i0; i--) { targetLoc = findLargest(x, i+1); swap(x, targetLoc, i); System.out.println("Pass " + (x.length-i) + ": " + Arrays.toString(x)); } } //-------------------------------------------------- // locates the largest value up through element size public static int findLargest(int[] x, int size) { int loc = 0; for (int i=1; i < size; i++) { if (x[loc] < x[i]) { loc = i; } } return loc; } //----------------------------------------- // Swaps element i with element j public static void swap (int[] x, int i, int j) { int temp = x[i]; x[i] = x[j]; x[j] = temp; } }