当前位置:网站首页>Blue Bridge Cup Quick sort (code completion)
Blue Bridge Cup Quick sort (code completion)
2022-07-04 07:11:00 【Woodenman Du】
requirement : Complete the code to achieve fast scheduling
Need to complete the code :
#include <stdio.h>
void swap(int a[], int i, int j)
{
int t = a[i];
a[i] = a[j];
a[j] = t;
}
int partition(int a[], int p, int r)
{
int i = p;
int j = r + 1;
int x = a[p];
while(1){
while(i<r && a[++i]<x);
while(a[--j]>x);
if(i>=j) break;
swap(a,i,j);
}
_____________________;
return j;
}
void quicksort(int a[], int p, int r)
{
if(p<r){
int q = partition(a,p,r);
quicksort(a,p,q-1);
quicksort(a,q+1,r);
}
}
int main()
{
int i;
int a[] = {50,49,48,48,47,46,1,3,5,2,4,6,30,30,30,30};
int N = 16;
quicksort(a, 0, N-1);
for(i=0; i<N; i++) printf("%d.", a[i]);
printf("\n");
return 0;
}
answer : swap(a,j,p);
analysis :
First
What is the process of quick platoon ?
1. Two points
2. Set benchmark
3. If it is smaller than the reference point, put it to the left of the reference point , If it is larger than the reference point, put it to the right of the reference point , And this process is realized by constantly finding qualified element exchange
Note that it is placed on both sides of the benchmark , One thing must be done after the exchange of qualified elements : Is the benchmark I selected not necessarily in the center of the eligible element , So we must exchange again , Let the benchmark go where it should be , The answer comes out
Sorting algorithm :https://blog.csdn.net/qq_59700927/article/details/122638158
边栏推荐
- Centos8 install mysql 7 unable to start up
- Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo
- uniapp小程序分包
- A new understanding of how to encrypt industrial computers: host reinforcement application
- 响应式移动Web测试题
- Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
- Paddleocr prompt error: can not import AVX core while this file exists: xxx\paddle\fluid\core_ avx
- Crawler (III) crawling house prices in Tianjin
- The most effective futures trend strategy: futures reverse merchandising
- 移动适配:vw/vh
猜你喜欢
Responsive - media query
[network data transmission] FPGA based development of 100M / Gigabit UDP packet sending and receiving system, PC to FPGA
Technical experts from large factories: common thinking models in architecture design
Centos8 install mysql 7 unable to start up
Campus network problems
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
Shopping malls, storerooms, flat display, user-defined maps can also be played like this!
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
uniapp小程序分包
随机推荐
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
"Sword finger offer" 2nd Edition - force button brush question
MySQL 45 learning notes (XI) how to index string fields
How can the old version of commonly used SQL be migrated to the new version?
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
Summary of MySQL common judgment functions!! Have you used it
Tar source code analysis Part 3
Crawler (III) crawling house prices in Tianjin
Boast about Devops
Google Chrome Portable Google Chrome browser portable version official website download method
2022年6月小结
Tar source code analysis Part 2
Latex中的单引号,双引号如何输入?
Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo
2022, peut - être la meilleure année économique de la prochaine décennie, avez - vous obtenu votre diplôme en 2022? Comment est - ce prévu après la remise des diplômes?
Vulhub vulnerability recurrence 77_ zabbix
大厂技术专家:架构设计中常用的思维模型
NLP literature reading summary
Download address of the official website of national economic industry classification gb/t 4754-2017
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction