1. 程式人生 > 其它 >聯盛德 HLK-W806 (四): 軟體SPI和硬體SPI驅動ST7735液晶LCD

聯盛德 HLK-W806 (四): 軟體SPI和硬體SPI驅動ST7735液晶LCD

import java.util.Arrays;

public class Hello {
    public static void quickSort(int[] arr,int low,int high){
        int i,j ,temp,t;
        if (low > high){
            return ;
        }

        i = low;
        j = high;
        temp = arr[low];

        while (i < j){
            while(i < j && arr[j] >=temp){
                j--;
            }

            while(i < j && arr[i] <= temp){
                i++;
            }

            if (i < j){
                t = arr[i];
                arr[i] = arr[j];
                arr[j] = t;
            }
        }
        // 基準歸位
        arr[low] = arr[i];
        arr[i] = temp;

        quickSort(arr,low,j-1);
        quickSort(arr,j+1,high);
    }


    public static void main(String[] args){
        int[] arr = {10,7,2,4,7,62,3,4,2,1,8,9,19};
        quickSort(arr, 0, arr.length-1);
        System.out.println(Arrays.toString(arr));
    }
}

  

import java.util.Arrays;

public class Hello {
    public static void quickSort(int[] arr,int low,int high){
        int i,j ,temp,t;
        if (low > high){
            return ;
        }

        i = low;
        j = high;
        temp = arr[low];

        while (i < j){
            while(i < j && arr[j] >=temp){
                j--;
            }
            arr[i] = arr[j]; // arr[i]的值已經被temp儲存了, 把右邊的值放到arr[i]位置

            while(i < j && arr[i] <  temp){
                i++;
            }
            arr[j] = arr[i]; // arr[j]的在上一步已經放到arr[i]裡面了 , 覆蓋不影響

        }
        // 因為最終 i=j時候退出迴圈  大於等於 或者小於等於都移動賦值了, 最後這個位置肯定是個坑,把基準填進來就行
        arr[i] = temp;

        quickSort(arr,low,j-1);
        quickSort(arr,j+1,high);
    }


    public static void main(String[] args){
        int[] arr = {10,7,2,4,7,10,3,4,2,1,8,9,19};
        quickSort(arr, 0, arr.length-1);
        System.out.println(Arrays.toString(arr));
    }
}