当前位置:网站首页>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;
}
边栏推荐
- Framework API online viewing source code
- Alibaba sentinel basic operation
- Bypass using the upper limit of the maximum number of regular backtracking
- Transport layer protocol parsing -- UDP and TCP
- [FreeRTOS] 10 event flag group
- Usage and introduction of MySQL binlog
- [training Day6] game [mathematics]
- Native applets are introduced using vant webapp
- Istio II traffic hijacking process
- Expression evaluation (stack)
猜你喜欢

Modbus communication protocol specification (Chinese) sharing

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
![[training Day10] point [enumeration] [bidirectional linked list]](/img/62/41dcab40eeb6aea545602e10c1c1a0.png)
[training Day10] point [enumeration] [bidirectional linked list]

API data interface of A-share transaction data

Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)

Software testing interview tips | if you don't receive the offer, I'll wash my hair upside down

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

VLAN Technology

How does starknet change the L2 landscape?

The difference between map and flatmap in stream
随机推荐
What is IDE (integrated development environment)
Install MySQL 5.7.37 on windows10
Upgrade appium automation framework to the latest 2.0
Machine learning job interview summary: five key points that resume should pay attention to
英文翻译中文常见脏话
[JVM] selection of garbage collector
[training Day9] rotate [violence] [thinking]
Alibaba sentinel basic operation
Rhodamine B labeled PNA | rhodamine b-pna | biotin modified PNA | biotin modified PNA | specification information
Lunch break train & problem thinking: thinking about the problem of converting the string formed by hour: minute: second to second
[training Day10] point [enumeration] [bidirectional linked list]
Appium element positioning - App automated testing
Substr and substring function usage in SQL
Luogu - p1616 crazy herb picking
Todolist case
TCP sliding window, singleton mode (lazy and hungry) double checked locking / double checked locking (DCL)
The U.S. economy continues to be weak, and Microsoft has frozen recruitment: the cloud business and security software departments have become the hardest hit
Valdo2021 - vascular space segmentation in vascular disease detection challenge (2)
Near infrared dye cy7.5 labeling PNA polypeptide experimental steps cy7.5-pna|188re labeling anti gene peptide nucleic acid (agpna)
The difference between map and flatmap in stream