当前位置:网站首页>Eight sorts --------- quick sort
Eight sorts --------- quick sort
2022-07-29 06:18:00 【Plum juice】

Find the benchmark number From left to right Set up two cursors each On the left If it is smaller than the reference number, the one on the right is larger than the reference number, then go inward , On the contrary, exchange the values pointed by the left and right cursors , When the left and right cursors meet Exchange the position of cursor and reference number Then take the benchmark number as the boundary Divide into two and continue to calculate
public static void main(String[] args) {
int [] arr = {7,6,5,4,2,1,3};
quickSort(arr,0, 6);
System.out.println(Arrays.toString(arr));
}
public static void quickSort(int[]arr,int left ,int right) {
if(left>right) {
return;
}
int base = arr[left];
int i = left;
int j = right;
while(i!=j) {
while(arr[j]>=base && i<j) {
j--;
}
while(arr[i]<=base && i<j) {
i++;
}
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
arr[left] = arr[i];
arr[i] =base ;
quickSort(arr, 0, i-1);
quickSort(arr, i+1, right);
}
边栏推荐
猜你喜欢

ABSA1: Attentional Encoder Network for Targeted Sentiment Classification

STM8S003国产替代 DP32G003 32 位微控制器芯片

HR must ask questions - how to fight with HR (collected from FPGA Explorer)

Based on STM32: couple interactive doll (design scheme + source code +3d drawing +ad circuit)

Huawei cloud 14 day Hongmeng device development -day7wifi function development

倾角传感器精度校准检测

基于51单片机的四路抢答器仿真

markdown与Typora

【软件工程之美 - 专栏笔记】13 | 白天开会,加班写代码的节奏怎么破?

HAL库学习笔记- 8 串口通信之使用
随机推荐
Ml9 self study notes
智能温度控制系统
NoClassDefFoundError 处理
mavan中的plugin位置
Multithreading and concurrency
动态加载数据
NOI Online 2022普及组 题解&个人领悟
Huawei cloud 14 day Hongmeng device development -day1 source code acquisition
HAL库学习笔记- 8 串口通信之使用
Ml self study notes 5
【软件工程之美 - 专栏笔记】22 | 如何为项目做好技术选型?
抽象封装继承多态
智慧充电桩系统由什么组成?
倾角传感器精度校准检测
兼容cc1101/cmt2300-DP4301 SUB-1G 无线收发芯片
进程与进程的概念
#6898 变幻的矩阵 题解
【软件工程之美 - 专栏笔记】26 | 持续交付:如何做到随时发布新版本到生产环境?
markdown与Typora
QT learning notes QT model/view