当前位置:网站首页>Insert sort of sort
Insert sort of sort
2022-07-28 07:13:00 【zhengyawen666】
One Algorithmic thought
Take ascending order as an example :
The first data is regarded as the sorted data , From the subscript for 1 The second data of starts sorting , Take this data as end. Need to put end+1 Insert the data of into the previous data , To form orderly data . Then open up a tmp Space , Store this data first , To prevent the subsequent data from moving backward as a whole and disappearing when inserting .
Will be tmp The data stored in the space is compared with the previous data one by one , If tmp Smaller than the previous data , Then we need to move the data of this position back one position ,tmp Then compare with the previous data . until tmp> Data for this location , Then insert the data into the next location of the location .( A data location has been reserved by moving ).
The above operation is a data insertion operation , All data needs to be operated , So set another layer of cycle control outside .
Two Code display
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
void insertsort(int* pa, int size)
{
assert(pa);
int i = 0;
for (i = 1; i <size-1; i++)
{
int end = i;
int tmp = pa[end + 1];
while (end >= 0)
{
if (tmp < pa[end])
{
pa[end + 1] = pa[end];
end--;
}
else
{
break;
}
}
pa[end+1] = tmp;
}
}
int main()
{
int a[] = { 11,25,6,87,98,69,30,23,10,2 };
int size = sizeof(a) / sizeof(a[0]);
insertsort(a, size);
int i = 0;
for (i = 0; i < size; i++)
{
printf("%d ", a[i]);
}
return 0;
}边栏推荐
- The.Joernindex database has no content after Joern runs
- MOOC Weng Kai C language week 7: array operation: 1. array operation 2. Search 3. preliminary sorting
- MySQL queries all descendant nodes under the parent node. When querying the user list, it is processed by multi-level (company) departments. According to reflection, it recurses the tree structure too
- Shell -- first day homework
- shell---条件语句练习
- Method of decomposing path into directory name and file name
- Standard C language learning summary 8
- C language push box
- Freemaker exports word with tables and multiple pictures to solve the repetition and deformation of pictures
- GFS分布式文件系统
猜你喜欢

DHCP service

Canvas drawing 1

MOOC翁恺C语言 第四周:进一步的判断与循环:1.逻辑类型与运算2.级联和嵌套的判断

Joern's code uses -devign

VNC Timed out waiting for a response from the computer

Install Nessus under Kali

主动扫描技术nmap详解

Metasploit penetration MS7_ 010 exercise

Results fill in the blank shopping list (teach you to solve it with Excel)

GFS分布式文件系统
随机推荐
Log in to Oracle10g OEM and want to manage the monitor program, but the account password input page always pops up
C language address book system
win下安装nessus
Softmax multi classification gradient derivation
VLAN configuration
在转化词向量之前先转化为AST再转化为词向量的实现方法
DNS domain name resolution
开虚拟机KALI2022.2下安装GVM
Small turtle C (Chapter 5 loop control structure program 567) break and continue statements
分解路径为目录名和文件名的方法
Tutorial on regularization
MOOC翁恺C语言第五周:1.循环控制2.多重循环3.循环应用
DOM -- page rendering, style attribute operation, preloading and lazy loading, anti shake and throttling
C language review (pointer)
shell---函数
Standard C language learning summary 5
关于正则的教程
Remotely access the local website of services such as neo4j on the ECS
RAID磁盘阵列
About gcc:multiple definition of
