java语言快速排序法

package mop;

public class e5 {

public static void main(String[]args)

{

int[]a={1,3,2,5,4,77,66,99,88,78};

int low=0,high=9;

qsort(a,low,high);

System.out.println("input:");

for(int i=0;i<10;i++)

{

System.out.print(a[i]+" ");

}

}

private static int Qpass(int[] a, int low,int high)

{

int x=a[low];

int key=a[low];

while(low<high)

{

while(low<high && a[high]>key)

high--;

if(low<high)

{

a[low]=a[high];

low++;

}

while(low<high && a[low]<=key)

low++;

if(low<high)

{

a[high]=a[low];

high--;

}

}

a[low]=x;

return low;

}


private static void qsort(int[]a,int low,int high)

{

if(low<high)

{

int pos=Qpass(a, low, high);

qsort(a,low,pos-1);

qsort(a,pos+1,high);

}

}

}


本文出自 “hagar” 博客,谢绝转载!

你可能感兴趣的:(java,快速排序法)