当前位置:网站首页>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
边栏推荐
- 同一个job有两个source就报其中一个数据库找不到,有大佬回答下吗
- 【网络数据传输】基于FPGA的百兆网/兆网千UDP数据包收发系统开发,PC到FPGA
- How to input single quotation marks and double quotation marks in latex?
- About how idea sets up shortcut key sets
- Data double write consistency between redis and MySQL
- MySQL 45 lecture learning notes (XIII) delete half of the table data, and the table file size remains the same
- MySQL 45 lecture learning notes (VII) line lock
- Knowledge payment applet dream vending machine V2
- [freertos] freertos Learning notes (7) - written freertos bidirectionnel Link LIST / source analysis
- How to share the source code anti disclosure scheme
猜你喜欢

Bottom problem of figure

Four sets of APIs for queues

Cell reports: Wei Fuwen group of the Institute of zoology, Chinese Academy of Sciences analyzes the function of seasonal changes in the intestinal flora of giant pandas

Vulhub vulnerability recurrence 77_ zabbix

果果带你写链表,小学生看了都说好

Vulhub vulnerability recurrence 76_ XXL-JOB

电脑通过Putty远程连接树莓派

selenium驱动IE常见问题解决Message: Currently focused window has been closed.

Computer connects raspberry pie remotely through putty

BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
随机推荐
flask-sqlalchemy 循环引用
Flink memory model, network buffer, memory tuning, troubleshooting
Tar source code analysis Part 3
Tar source code analysis Part 7
Transition technology from IPv4 to IPv6
Tar source code analysis Part 2
Pangu open source: multi support and promotion, the wave of chip industry
[freertos] freertos Learning notes (7) - written freertos bidirectionnel Link LIST / source analysis
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
[MySQL transaction]
Cervical vertebra, beriberi
Analysis of tars source code 5
【FPGA教程案例8】基于verilog的分频器设计与实现
Download address of the official website of national economic industry classification gb/t 4754-2017
【FPGA教程案例7】基于verilog的计数器设计与实现
Summary of MySQL common judgment functions!! Have you used it
高薪程序员&面试题精讲系列119之Redis如何实现分布式锁?
Introduction to spark core components
Selenium ide plug-in download, installation and use tutorial
Master-slave replication principle of MySQL database