public class Sorter {
  
  /**
   * Put elements in list into non-descending order.  The resulting
   * list contains the same elements as before, but (possibly) in
   * a different order.
   */
  public static void insertionSort(int[] list) {
    // list[0..i-1] is in order
    for (int i= 0; i != list.length;i++) {
    // Put list[i] where it belongs in list[0..i], possibly
      // moving the larger elements up.
      int j, s= list[i];
      for (j= i; j != 0 && list[j-1] > s; j--) {
        list[j]= list[j-1];
      }
      list[j] = s;
    }
  }
  
  /**
   * Put elements in list into non-descending order.  The resulting
   * list contains the same elements as before, but (possibly) in
   * a different order.
   */
  public static void selectionSort(int[] list) {
    // list[0..i-1] is in order
    for (int i= 0; i != list.length; i++) {
      // Find the smallest element in list[i..list.length-1]
      // and put it into list[i]
      int s= i;
      for (int j= i; j != list.length; j++) {
        if (list[s] > list[j]) {
              s= j;
        }
      }
      // swap list[s] and list[i]
      int swap= list[s];
      list[s]= list[i];
      list[i]= swap;
    }
  }
}