/Users/johnr/Dropbox/johnrayworth.info/largeFilesOutsideJSR/__IB-Other/Other/IA-Solutions-2019/TigerBee/Product/Computer Science Ia/src/computer/science/ia/SortAndSearchFlight.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 computer.science.ia;
 7 
 8 import java.util.ArrayList;
 9 
10 /**
11  *
12  * @author 19515
13  */
14 public class SortAndSearchFlight {
15 
16     public void selectionSortOfFlightCodes(ArrayList<Flight> flights) {
17         for (int i = 0; i < flights.size() - 1; i++) {
18             int minIndex = i;      // Assumed index of smallest remaining value.
19             for (int j = i + 1; j < flights.size(); j++) {
20                 if (flights.get(j).getCityCode().compareTo(flights.get(minIndex).getCityCode()) < 0) {
21                     minIndex = j;  // Remember index of new minimum
22                 }
23             }
24             if (minIndex != i) {
25                 //Exchange current element with smallest remaining.
26                 //But note that this only happens once each outer loop iteration, at the end of the inner loop's looping
27                 Flight temp = flights.get(i);
28                 flights.set(i, flights.get(minIndex));
29                 flights.set(minIndex, temp);
30             }
31         }
32     }
33 
34 }
35