标签:
(java版)
public class Qsort {
static int Partition(int l[],int low,int high){
int prvotkey = l[low];
while(low<high){
while(low<high && l[high] >= prvotkey)
high--;
l[low] = l[high];
while(low<high && l[low] <= prvotkey)
low++;
l[high] = l[low];
}
l[low] = prvotkey;
return low;
}
static void QSort(int l[],int low, int high){
int prvotkey;
if(low < high){
prvotkey = Partition(l,low,high);
QSort(l,low,prvotkey-1);
QSort(l,prvotkey+1,high);
}
else{
// System.out.println("error!");
}
}
static void quicksort(int l[],int n){
QSort(l,0,n-1);
}
public static void main(String[] args) {
int a[] = {0,2,5,43,32,65,43,21,87,1};
int b;
for(b=0; b<10;b++){
System.out.print(a[b]+ " ");
}
System.out.println();
quicksort(a,10);
int c;
for(c = 0; c<10 ; c++){
System.out.print(a[c]+" ");
}
}
}
标签:
原文地址:http://www.cnblogs.com/tangtang-123/p/4436034.html