当前位置:网站首页>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);
}
边栏推荐
- STM32 MDK(Keil5) Contents mismatch错误总结
- STM32 printf问题总结 semihosting microLIB理解
- 智慧能源管理系统解决方案
- Huawei cloud 14 day Hongmeng device development -day2 compilation framework
- 基于51单片机ADC0808的proteus仿真
- Reading papers on fake news detection (2): semi supervised learning and graph neural networks for fake news detection
- 抽象类以及接口
- 2022 spring recruit - Hesai technology FPGA technology post (one or two sides, collected from: Digital IC workers and FPGA Explorers)
- QT learning notes QtSql
- IDEA 实用快捷键 新手必看
猜你喜欢
随机推荐
Hal learning notes - Basic timer of 7 timer
Model building in pytorch
【软件工程之美 - 专栏笔记】17 | 需求分析到底要分析什么?怎么分析?
Joiner.on和stream().map联合使用技巧
2022 spring recruit - Hesai technology FPGA technology post (one or two sides, collected from: Digital IC workers and FPGA Explorers)
NOI Online 2022普及组 题解&个人领悟
传统模型预测控制轨迹跟踪——波浪形轨迹(功能包已经更新)
一些工具,插件,软件链接分享给大家~
基于51单片机的直流电机调速系统(L298的使用)
基于msp430f2491的proteus仿真(实现流水灯)
STM32FF030 替代国产单片机——DP32G030
给二维表添加时间序列索引
JUC并发知识点
TB6600+stm32F407测试
智能货架安全监测系统
IDEA 实用快捷键 新手必看
Multithreading and concurrency
Design and implementation of QT learning notes data management system
基于msp430f2491的proteus仿真
FT232替代GP232RL USB-RS232转换器芯片国产化应用









