快速排序

来源:互联网 发布:淘宝付款失败钱扣了 编辑:程序博客网 时间:2024/06/07 15:31
/** * 快速排序 * @author Joban * */public class quickSort {    public static void main(String[] args) {        // TODO Auto-generated method stub        int a[] = {2,5,3,1,4,9,2,3,1,1};        sort(a, 0, a.length-1);        for(int x :a){            System.out.print(x+" ");        }    }    public static void sort(int a[],int low,int high) {        int i = low;        int j = high;        if (low>high){            return;        }        int temp = a [low];        while(i<j){            while(i<j&&a[j]>=temp){                j--;            }            if (i<j){                a[i] = a[j];            }            while (i<j&&a[i]<=temp) {                i++;            }            if(i<j){                a[j]=a[i];            }        }        a[i] = temp;        sort(a, low, i-1);        sort(a, i+1, high);    }}
1 0
原创粉丝点击