スナップアルゴリズム実装
2317 ワード
public class QuickSort {
public static void sort(int arr[],int low,int high){
int l=low;
int h=high;
int temp=arr[low];
while(l<h)
{
while(l<h&&arr[h]>=temp) h--;
arr[l]=arr[h];
while(l<h&&arr[l]<=temp) l++;
arr[h]=arr[l];
}
System.out.println("h:"+h+" l:"+l);
arr[l]=temp;
if(l>low)sort(arr,low,h-1);
if(h<high)sort(arr,l+1,high);
}
public static void main(String[] args)
{
int a[]={5,8,7,1,3,2,6,4};
sort(a,0,a.length-1);
for(int i=0;i<a.length;i++)
System.out.print(a[i]+" ");
}
}