import java.util.Random;

public class TimeSort {
  
  private static Random rand = new Random();
  
  /**
   * Generates a random list of integers of length "N".
   * 
   * Runs our three sorting algorithms on it and prints their stats.
   */
  public static void timeRandom(int N) {
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = rand.nextInt();
    }
    
    timeThem(A);
  }
  
  /**
   * Generates a sorted list of integers of length "N".
   * 
   * Runs our three sorting algorithms on it and prints their stats.
   */
  public static void timeSorted(int N) {
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = i;
    }
    
    timeThem(A);
  }
  
  /**
   * Generates a reverse-sorted list of integers of length "N".
   * 
   * Runs our three sorting algorithms on it and prints their stats.
   */
  public static void timeReversed(int N) {
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = N - i;
    }
    
    timeThem(A);
  }
  
  /**
   * Runs our three algorithms on a list of integers.
   */
  public static void timeThem(int[] A) {
    int N = A.length;
    
    // make three copies so that each algorithm has
    // to sort the same input.
    int[] A1  = new int[N];
    int[] A2 = new int[N];
    int[] A3 = new int[N];
    
    for (int i = 0; i < N; i++) {
      A1[i] = A[i];
      A2[i] = A[i];
      A3[i] = A[i];
    }
    
    System.out.println("bubbleSort " + N + ": ");
    Sort.bubbleSort2(A1);
    System.out.println("insertionSort " + N + ": ");
    Sort.insertionSort(A2);
    System.out.println("selectionSort " + N + ": ");
    Sort.selectionSort(A3);
  }
  
  public static void main(String[] args) {
    int SIZE = 100;
    
    System.out.println("BEST CASE (sorted)");
    timeSorted(SIZE);
    System.out.println();
    
    System.out.println("INTERMEDIATE CASE (random)");
    timeRandom(SIZE);
    System.out.println();
    
    System.out.println("WORST CASE (reversed)");
    timeReversed(SIZE);
    System.out.println();
    
  }
  
}

