简单排序算法

快速排序

    private void quickSort(int[] a, int start, int end) {
        if (start >= end) {
            return;
        }
        int s = start, e = end;
        int mid = s;
        while (s < e) {
            if (mid < e) {
                if (a[mid] <= a[e]) {
                    e--;
                    continue;
                } else {
                    int temp = a[e];
                    a[e] = a[mid];
                    a[mid] = temp;
                    mid = e;
                    continue;
                }
            }
            if (mid > s) {
                if (a[mid] >= a[s]) {
                    s++;
                    continue;
                } else {
                    int temp = a[s];
                    a[s] = a[mid];
                    a[mid] = temp;
                    mid = s;
                    continue;
                }
            }
        }
        quickSort(a, start, mid-1);
        quickSort(a, mid+1, end);
    }

冒泡排序

    private void maoPao(int[] a) {
        int len = a.length;
        for (int i = len-1;i > 0; i--) {
            for (int j=0;j a[j+1]) {
                    int temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }
    }

你可能感兴趣的:(简单排序算法)