当前位置:网站首页>Quick sort
Quick sort
2022-07-24 20:30:00 【To catty Hawthorn】
/*
Quick sort
thought , Divide and conquer , Select an element first , Make him reach the position where the final sorting is completed , here , His left element must
Smaller than him , The right side must be greater than , Then quickly arrange the arrays on both sides .
*/
#include<iostream>
using namespace std;
void QuickSort(int a[],int s,int e)
{
if(s >= e) return;
int i =s,j=e;
int pivot = a[s];
while(i != j){
while(i < j && a[j] >= pivot) j--; // Be careful , You need an equal sign , a[j] >= pivot, Or you won't get out
swap(a[i],a[j]);
while(i < j && a[i] <= pivot) i++;
swap(a[i],a[j]);
}
QuickSort(a,s,i-1);
QuickSort(a,i+1,e);
}
int main()
{
int a[] = {93,27,30,2,8,12,2,8,30,89};
int size = sizeof(a) / sizeof(int);
QuickSort(a,0,size - 1);
for(int i = 0;i < size;++i)
cout << a[i] << " ";
cout << endl;
return 0;
}
边栏推荐
- Apache atlas version 2.2 installation
- [basic data mining technology] KNN simple clustering
- [training Day8] [luogu_p6335] staza [tarjan]
- Markdown to PDF API data interface
- Valdo2021 - vascular space segmentation in vascular disease detection challenge (2)
- Inconsistent time
- Solve the problem of error l6218e undefined symbol XXX
- VLAN Technology
- Choose the appropriate container runtime for kubernetes
- Work notes - some problems encountered when using jest
猜你喜欢
![[training Day8] [luogu_p6335] staza [tarjan]](/img/cf/e2027549c56b8597e7cd579d737392.png)
[training Day8] [luogu_p6335] staza [tarjan]

API data interface of A-share transaction data

Opengl rendering pipeline

Home Assistant中接入博联WiFi智能遥控

Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)
![[shader realizes the flicker effect of three primary colors of television signal _shader effect Chapter 5]](/img/ca/fa87bc199f3aefebddf6eb58784dc7.png)
[shader realizes the flicker effect of three primary colors of television signal _shader effect Chapter 5]

Synthesis of peptide nucleic acid PNA labeled with heptachydrin dye cy7 cy7-pna

147-利用路由元信息设置是否缓存——include和exclude使用——activated和deactivated的使用
![[msp430g2553] graphical development notes (2) system clock and low power consumption mode](/img/4e/c08288c3804d3f1bcd5ff2826f7546.png)
[msp430g2553] graphical development notes (2) system clock and low power consumption mode

Chrome realizes automated testing: recording and playback web page actions
随机推荐
Work notes - some problems encountered when using jest
英文翻译中文常见脏话
Do you want to enroll in a training class or study by yourself?
Home Assistant中接入博联WiFi智能遥控
Safe way -- Analysis of single pipe reverse connection back door
Modulenotfounderror: no module named 'pysat.solvers' (resolved)
Mass modify attribute values in objects in JS
Hcip early summary
Leetcode 206 reverse linked list, 3 longest substring without repeated characters, 912 sorted array (fast row), the kth largest element in 215 array, 53 largest subarray and 152 product largest subarr
【LeetCode】1184. 公交站间的距离
PHP page Jump mode
Apache atlas version 2.2 installation
[training Day6] game [mathematics]
Preview and save pictures using uni app
Bypass using the upper limit of the maximum number of regular backtracking
In the era of new knowledge economy, who is producing knowledge?
What is IDE (integrated development environment)
Software testing interview tips | if you don't receive the offer, I'll wash my hair upside down
Generate self signed certificate: generate certificate and secret key
Guys, I have no problem running locally in diea, running on the server. What's wrong with the lack of CDC connection? The database IP can be pinged