当前位置:网站首页>Common sorting methods
Common sorting methods
2022-06-30 07:30:00 【My deep blue】
Common sorting methods
Exchange class sorting
1、 Bubble sort
The idea is to compare two adjacent elements
When using bubble sort , Only one best value can be selected at a time , Yes n The maximum number of elements to execute (n - 1) Compare it to

#include "stdio.h"
void main()
{
int a[10];
int i, j, temp;
printf("Please input ten numbers: \n");
for (i = 0; i < 10; i++)
scanf("%d", &a[i]);
for (i = 0; i < 9; i++) // 10 Number ,10 - 1 Wheel bubbling , Each round pushes the current maximum number to the end
{
for (j = 0; j < 9 - i; j++) // 9 - i, It means that after a round of bubbling , Just reduce one comparison
if (a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
for (i = 0; i < 10; i++)
printf("%d\n", a[i]);
}
2、 Quick sort
Is the process of finding the correct index position for benchmark data .
Select a benchmark value during each sorting , Then compare all elements with the benchmark value , And divided into two piles according to the size , Then execute the process recursively , Until all elements are sorted .
1> Take a number from the sequence as the reference number first .
2> Partition process , Put all the larger numbers to the right of it , Less than or equal to its number all put it to the left .
3> Repeat the second step for the left and right sections , Until there is only one number in each interval .

Insert class sort
1、 Simple insertion sort
2、 Hill sort
Select the sort of class
1、 Simple selection sequencing
2、 Push sort method
边栏推荐
猜你喜欢

网络安全-抓包和IP包头分析

app quits unexpectedly

C language implementation sequence stack

Stm32g0 porting FreeRTOS

系统软件开发基础知识

How crazy are young people in sideline industry: 3000 monthly salary and 3W sideline income

Raspberry pie 4B Getting Started Guide

Parameter calculation of deep learning convolution neural network

Application of stack -- using stack to realize bracket matching (C language implementation)

Network security - packet capture and IP packet header analysis
随机推荐
LabVIEW程序代码更新缓慢
Examen final - notes d'apprentissage PHP 6 - traitement des chaînes
The maximum expression in Oracle database message list is 1000 error
Minecraft 1.16.5模组开发(五十) 书籍词典 (Guide Book)
Parameter calculation of deep learning convolution neural network
将本地电脑文件复制到虚拟机系统中详细方法
Vs2019 and SQL
grep命令用法
[most complete] install MySQL on a Linux server
Promise async/await
C language implements sequential queue, circular queue and chain queue
Digital tube EEPROM key to save value
嵌入式测试流程
Similarities and differences of differential signal, common mode signal and single ended signal (2022.2.14)
Network security - routing principle
Mailbox application routine of running wild fire RT thread
app quits unexpectedly
Basic knowledge points
Can introduction
Detailed analysis of message signals occupying multiple bytes and bits