* 快速排序是最流行的排序算法
* 然後遞歸地調用自身為每一個子數組進行快速排序來實現
* ArrayIns
* l
*/
package linzhanghui
public class ArrayIns {
private long[] theArray;
private int nElems;
public ArrayIns(int max) {
theArray = new long[max];
nElems =
}
public void insert(long value) {
theArray[nElems] = value;
nElems++;
}
public void display() {
System
for(int j=
System
System
}
public void quickSort() {
recQuickSort(
}
public void recQuickSort(int left
if(right
return;
else {
long pivot = theArray[right];
int partition = partitionIt(left
recQuickSort(left
recQuickSort(partition+
}
}
public int partitionIt(int left
int leftPtr = left
int rightPtr = right;
while(true) {
while( theArray[++leftPtr] < pivot)
;
while(rightPtr >
;
if(leftPtr >= rightPtr)
break;
else
swap(leftPtr
}
swap(leftPtr
return leftPtr;
}
public void swap(int dex
long temp = theArray[dex
theArray[dex
theArray[dex
}
}
/*
* 程序隨機產生
* l
*/
package linzhanghui
public class QuickSortApp {
public static void main(String[] args) {
int maxSize =
ArrayIns arr;
arr = new ArrayIns(maxSize)
for(int j=
long n = (int)(java
arr
}
arr
arr
arr
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26174.html