/Users/johnr/Dropbox/johnrayworth.info/largeFilesOutsideJSR/__IB-Other/Other/IA-Solutions-2019/Alex/Product/BeachPicker/src/com/hyltonboy/beachpicker/util/Sort.java
 1 /*
 2  * To change this license header, choose License Headers in Project Properties.
 3  * To change this template file, choose Tools | Templates
 4  * and open the template in the editor.
 5  */
 6 package com.hyltonboy.beachpicker.util;
 7 
 8 import com.hyltonboy.beachpicker.place.Place;
 9 
10 /**
11  *
12  * @author 18719
13  */
14 public class Sort {
15     public static Place[] selectionSort(Place[] intArray) {
16     for (int i = 0; i < intArray.length-1; i++) {
17         int minIndex = i;      // Assumed index of smallest remaining value.
18         for (int j = i+1; j < intArray.length; j++) {
19             if (intArray[j].getDistance() < intArray[minIndex].getDistance() ) {
20                 minIndex = j;  // Remember index of new minimum
21             }
22         }
23         if (minIndex != i) { 
24             //Exchange current element with smallest remaining.
25                          //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
26             Place temp = intArray[i];
27             intArray[i] = intArray[minIndex];
28             intArray[minIndex] = temp;
29         }
30     }
31     return intArray;
32 }
33 }
34