Esempio n. 1
0
 @Override
 public void sort(VisualArray array) {
   for (int i = array.getArraySize() - 1; i >= 1; --i) {
     for (int j = 0; j < i; ++j) {
       array.compareAndSwap(j + 1, j);
     }
     array.changeState(i, ArrayState.SORTED);
   }
   array.changeState(0, ArrayState.SORTED);
 }
Esempio n. 2
0
  private void sort(VisualArray array, int start, int end) {
    if (start == end) return;

    array.changeState(start, end, ArrayState.INACTIVE);

    int splitPivot = start;
    int pivot = end - 1;

    for (int i = start; i < end - 1; ++i) {
      if (array.compare(i, pivot)) {
        array.compareAndSwap(i, splitPivot);
        array.changeState(splitPivot, ArrayState.INACTIVE);
        ++splitPivot;
      } else array.countCompare();
    }

    swap(array, pivot, splitPivot);
    pivot = splitPivot;
    array.changeState(pivot, ArrayState.SORTED);
    array.changeState(pivot + 1, end, ArrayState.INACTIVE);

    sort(array, start, pivot);
    sort(array, pivot + 1, end);
  }