示例#1
0
  private void swap(VisualArray array, int i, int j) {
    array.countSwap();

    int temp = array.getIndexValue(i);
    array.setIndexValue(i, array.getIndexValue(j));
    array.setIndexValue(j, temp);
  }
示例#2
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);
 }
示例#3
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);
  }
示例#4
0
 @Override
 public void sort(VisualArray array) {
   sort(array, 0, array.getArraySize());
 }