当前位置:网站首页>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);
}
边栏推荐
猜你喜欢

FPGA based: moving target detection (supplementary simulation results, available)

Based on stc51: schematic diagram and source code of four axis flight control open source project (entry-level DIY)

【软件工程之美 - 专栏笔记】14 | 项目管理工具:一切管理问题,都应思考能否通过工具解决

新能源共享充电桩管理运营平台

循环链表和双向链表

传统模型预测控制轨迹跟踪——圆形轨迹(功能包已经更新)

Jingwei Qili: OLED character display based on hmep060 (and Fuxi project establishment demonstration)

Logistic regression - project practice - credit card detection task (Part 2)

CS5340国产替代DP5340多比特音频 A/D 转换器

Hal library learning notes-13 application of I2C and SPI
随机推荐
新能源充电桩后台管理系统平台
基于AD9850的多功能信号发生器
Hal library learning notes-12 SPI
简洁代码实现pdf转word文档
基于msp430f2491的proteus仿真(实现流水灯)
2022 spring move - core technology FPGA development post pen test question (original question and experience)
【RoboMaster】A板接收JY-ME01角度传感器数据--modebus协议&CRC软件校验
Joiner.on和stream().map联合使用技巧
循环链表和双向链表
【软件工程之美 - 专栏笔记】30 | 用好源代码管理工具,让你的协作更高效
智能货架安全监测系统
爬虫Requests库的一些简单用法
基于msp430f2491的proteus仿真
噪声传感器工作原理是什么?
【软件工程之美 - 专栏笔记】29 | 自动化测试:如何把Bug杀死在摇篮里?
顺序表和链表
STM32 MDK(Keil5) Contents mismatch错误总结
QT learning notes QT model/view
FPGA based: multi-target motion detection (hand-in-hand teaching ①)
SimpleFOC调参3-PID参数整定攻略