コード例 #1
0
  // insertion sort (n^2)   ///bien
  public int InsertionSort(T a[]) {
    int comparaciones = 0;
    for (int i = 1; i < a.length; i++) {
      T aux = a[i];
      int j = i - 1;
      comparaciones++;
      while (j >= 0 && aux.compareTo(a[j]) < 0) {

        a[j + 1] = a[j]; // haces el hueco para insercion
        j--;
      }
      a[j + 1] = aux; // insertas elemento
    }
    return comparaciones;
  }