/Users/johnr/Dropbox/johnrayworth.info/largeFilesOutsideJSR/__IB-Other/Other/IA-Solutions-2019/Proud/Product/ComputerScienceInternalAssessmentV2/src/computerscienceinternalassessment/SortAndSearchPalettes.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 computerscienceinternalassessment;
 7 
 8 import java.util.ArrayList;
 9 
10 /**
11  *
12  * @author 14914
13  */
14 public class SortAndSearchPalettes {
15     
16     public void selectionSortOfPalettes(ArrayList<Palette> palettes) {
17     for (int i = 0; i < palettes.size(); i++) {
18         int minIndex = i;      // Assumed index of smallest remaining value.
19         for (int j = i+1; j < palettes.size(); j++) {
20             if (palettes.get(j).getPaletteName().compareTo(palettes.get(minIndex).getPaletteName()) < 1  ) {
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             Palette temp = palettes.get(i);
28             palettes.set(i, palettes.get(minIndex));
29             palettes.set(minIndex, temp);
30         }
31     }
32 }
33     
34     
35     
36 }
37