当前位置:网站首页>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;
}边栏推荐
- Standard C language learning summary 8
- DNS域名解析
- Differences and relationships among NPM, Yran and NPX
- DHCP服务
- Results fill in the blanks carelessly (violent solution)
- C language address book system
- MOOC翁恺C语言 第六周:数组与函数:1.数组2.函数的定义与使用3.函数的参数和变量4.二维数组
- JS string method Encyclopedia
- Layer 3 switching and VRRP
- Standard C language learning summary 7
猜你喜欢

Remotely access the local website of services such as neo4j on the ECS

Install Nessus under Kali

Freemaker exports word with tables and multiple pictures to solve the repetition and deformation of pictures

DHCP service

Group management and permission management

The.Joernindex database has no content after Joern runs

NAT network address translation

rsync+inotify实现远程实时同步

DOM -- page rendering, style attribute operation, preloading and lazy loading, anti shake and throttling

VNC Timed out waiting for a response from the computer
随机推荐
Codesensor: convert the code into AST and then into text vector
metasploit渗透ms7_010练习
Bond mode configuration
Easypoi export table with echars chart
ELK日志分析系统的部署
Differences and relationships among NPM, Yran and NPX
Redis哨兵模式及集群
Static and floating routes
joern运行后.joernindex数据库无内容
Canvas drawing 2
MOOC翁恺 C语言 第三周:判断与循环:1.判断
Es6--- > arrow function, class, modularization
MOOC Weng Kai C language week 3: judgment and cycle: 1. Judgment
MOOC翁恺C语言第八周:指针与字符串:1.指针2.字符类型3.字符串4.字符串计算
多进程(多核运算)Multiprocessing
MOOC翁恺C语言 第六周:数组与函数:1.数组2.函数的定义与使用3.函数的参数和变量4.二维数组
Read the IP and device information of the switch node in the XML file, Ping the device, and the exception is displayed in the list
Blue Bridge Cup square filling number
C language address book system
DOM operation cases
