/Users/johnr/Desktop/IA_14_-_Stage_P_Upload_all_2021-04-08/RugbyIA Pune April 7th/src/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 
 7 /**
 8  *
 9  * @author 20564
10  */
11 public class Sort {
12     public void sortByGameNumber(Game[] gamesArray, int counter) {
13         int n = counter;
14         boolean sorted = false;
15         while (!sorted) {
16             n--; //It is the n which will result in one less comparison happening each outer pass;
17                //whereas, with the first bubble sort we could use the 'pass' variable used for the for loop.
18             sorted = true;  
19             for (int i=0; i < n; i++) {
20                 if (gamesArray[i].getGameNumber().compareTo(gamesArray[i+1].getGameNumber()) > 0) {
21                     Game temp = gamesArray[i];  
22                     gamesArray[i] = gamesArray[i+1];  
23                     gamesArray[i+1] = temp;
24                     sorted = false; //as in the second bubble sort, if swapping happens we'll want to continue, and so
25                                     //with sorted re-set to false again, the while loop continues
26                     //System.out.println("Inside sort by artist");
27                 }
28             }
29         }
30     }
31 }
32 
33 
34