• java数据结构-排序算法-快排算法


    package com.kuang;

    import java.lang.reflect.Array;
    import java.util.Arrays;

    /**
    * @auther 付强
    * @date 2020/2/14 - 18:39
    */
    public class quickSort {
    public static void main(String[] args) {
    int[] arr=new int[]{3,4,11,1,0,6,4,8};
    //即arr[0]为start,结尾为end
    quickSort(arr,0,arr.length-1);
    System.out.println(Arrays.toString(arr));
    }
    public static void quickSort(int[] arr,int start,int end){
    if(start<end) {
    //把数组中第n个数字作为标准数
    int stard = arr[start];
    //记录所需要排序的小标
    int low = start;
    int high = end;
    //虚幻找出比标准数大的数和比标准数小的数
    while (low < high) {
    //右边的数字比标准数大
    while (low < high && stard <= arr[high]) {
    high--;
    }
    arr[low] = arr[high];
    //右边的数字比标准数小的时候
    while (low < high && stard >= arr[low]) {
    low++;
    }
    arr[high] = arr[low];
    }
    //此时low=high,把标准数赋给相等的值
    arr[low] = stard;
    //处理所有小的数字
    quickSort(arr, start, low);
    //处理所有大的数字
    quickSort(arr, low + 1, end);
    }

    }
    }
  • 相关阅读:
    P2P编程(十)
    9.25
    9.22
    pycharm常用快捷命令
    sublime常用快捷方式
    3.1
    总想听你说起不曾喜欢你
    1.1
    python 网络编程和并发编程题
    知识点梳理 网络基础
  • 原文地址:https://www.cnblogs.com/fuqiang-java/p/12308554.html
Copyright © 2020-2023  润新知