AcWing 785. 快速排序(java)【快速排序】

谢谢y老师模版和大佬们题解❤️

年轻y总好帅爱了爱了❤️

有输入输出版

java:

AcWing 785. 快速排序(java)【快速排序】_第1张图片

 

import java.util.*;

public class Main{
    private static int N = 100010;
    private static int[] q = new int[N];
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for(int i = 0; i = r){
            return;
        }
        int x = q[l + r >> 1];
        int i = l - 1;
        int j = r + 1;
        
        while(i < j){
            do i ++; while (q[i] < x);
            do j --; while (q[j] > x);
            if(i < j){
                int tmp = q[i];
                q[i] = q[j];
                q[j] = tmp;
            }
        }
        quicksort(q, l ,j);
        quicksort(q, j + 1, r);
    }
}

你可能感兴趣的:(和y总约会❤️,acwing,java)