zoukankan      html  css  js  c++  java
  • QuickSortDemo

    package com.suning.sntcscase.controller.MutiThread;
    
    import static jdk.nashorn.internal.objects.Global.print;
    
    public class QuickSortDemo {
    
        public static void main(String[] args) {
            int[] arr = {5, 6, 7, 81, 2, 66, 88, 17, 99};
             printArr(arr);
            quickSort(arr, 0, arr.length - 1);
            System.out.println();
            printArr(arr);
        }
    
        private static void printArr(int[] arr) {
            for(int i=0;i<arr.length; i++){
                System.out.print(arr[i] +"	");
            }
        }
    
        private static void quickSort(int[] arr, int low, int high) {
            int start = low;
            int end = high;
            int key = arr[low];
    
            //从右往左找小
            while (end > start) {
    
                while (end > start && arr[end] >= key)
                    end--;
    
                if (arr[end] <= key) {
                    int tmp = arr[end];
                    arr[end] = arr[start];
                    arr[start] = tmp;
                }
    
    
                //从左往右大
                while (end > start && arr[start] <= key)
                    start++;
    
    
                if (arr[start] >= key) {
                    int tmp = arr[start];
                    arr[start] = arr[end];
                    arr[end] = tmp;
                }
    
            }
    
            ///递归
         if(start <low)   quickSort(arr,0,start-1);
         if(end <high)   quickSort(arr,end+1,high);
    
    
    
    
        }
    
    
    
    
    
    
    }
    

      

  • 相关阅读:
    2.socket编程
    1网络编程基础概念
    vim笔记
    mysql示例及练习2
    mysql的示例及练习
    自己封装的mysql应用类示例
    mysql3_pymysql
    mysql2
    mysql1
    python之列表与集合
  • 原文地址:https://www.cnblogs.com/alamps/p/11685287.html
Copyright © 2011-2022 走看看