public class SelectionSort  {
  /** 11/14/2018
    * This class demonstrates Selection Sort algorithm
    * we do it with and without a swap method
    */
  public static void main(String[] args) {
    // declare and initialize 
    int[] numbers = {3, 4, 2, 1, 0, 0, 0, 1, 5};
    selectionSort1(numbers);
    for (int num: numbers)
      System.out.println(num);
    System.out.println("integers array: ");
    int[] integers = {9, 8, 6, 3, 2, 10};
    selectionSort2(integers);
    for (int num: integers)
      System.out.println(num);
  }
    
  /** Selection sort repeatedly finds the minimum of the rest of
    * the array, and puts it at loc i.
    * Version 1 does NOT use a method for swapping
    */
  public static void selectionSort1(int[] arr)  {
    // outer loop: consider loc i as the running min
    for (int i=0; i<arr.length-1; i++) {
      // inner loop checks rest of the array for a smaller value
      for (int j=i+1; j<arr.length; j++) {
          if (arr[i]>arr[j])  {  // then SWAP
             int temp = arr[i];
             arr[i] = arr[j];
             arr[j] = temp;
          } // end if
      } // end inner loop for j
    } // end outer loop for i
  } // end method
  
  /** Selection sort repeatedly finds the minimum of the rest of
    * the array, and puts it at loc i.
    * Version 2 uses a method for swapping
    */
  public static void selectionSort2(int[] arr)  {
    // outer loop: consider loc i as the running min
    for (int i=0; i<arr.length-1; i++) {
      // inner loop checks rest of the array for a smaller value
      for (int j=i+1; j<arr.length; j++) {
          if (arr[i]>arr[j])  {  // then SWAP values at loc i and j
             swap(arr, i, j);
          } // end if
      } // end inner loop for j
    } // end outer loop for i
  } // end method

  public static void swap(int[] arr, int index1, int index2) {
          int temp = arr[index1];
          arr[index1] = arr[index2];
          arr[index2] = temp;
  }
}


/**LAB: Write a class with a main method and 2 other methods:
  * 1. Create a character array, fill it up with characters,
  * and return the array.
  * 2. Sort the character array.
  * 3. main will call both methods, and in main you will print the
  * unsorted array and then the sorted array.
  */












