当前位置:网站首页>C语言:随机生成数+插入排序
C语言:随机生成数+插入排序
2022-07-27 07:35:00 【念迟鱼学编程】
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAXSIZE 10
void initArr(int arr[] , int length);
void showArr(int arr[] , int length);
void inserSort(int arr[] , int length);
int main()
{
srand((unsigned int)time(NULL));
int arr[MAXSIZE];
printf("==========排序前的序列=============\n");
initArr(arr,MAXSIZE);
showArr(arr,MAXSIZE);
printf("==========插入排序后的序列=============\n");
inserSort(arr,MAXSIZE);
showArr(arr,MAXSIZE);
system("pause");
return 0;
}
void initArr(int arr[] , int length)
{
for(int i = 0 ; i < length ; i++){
arr[i] = rand()%20;
}
}
void showArr(int arr[] , int length)
{
for(int i = 0 ; i < length ; i++){
printf("%4d",arr[i]);
}
printf("\n");
}
void inserSort(int arr[] , int length)
{
//插入排序
for(int i = 1 ; i < length ; i++){
for(int j = i ; j >= 1 && arr[j] < arr[j-1] ; j--){
int temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] = temp;
}
}
}
边栏推荐
- Apifox安装及使用
- glGetUniformLocation,glUniform4f
- Codeforces Round #810 (Div.2) A-C
- The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly 100 times the improvement of analysis performance
- 我是不是被代码给耽误了……不幸沦为一名程序员……
- Understanding and learning of node flow and processing flow in io
- 实用的新药研发项目管理平台
- JS regular expression implementation adds a comma to every three digits
- User unlock sm04 sm12
- C#委托的使用案例
猜你喜欢

存储过程与函数

Grayog log server single node deployment

电子量产项目框架--基本思想

什么是真正的 HTAP ?(二)挑战篇

Clickhouse notes 1 | introduction, features | installation and use based on centos7 system | common data types | mergetree table engine | SQL operation

Mysql: increase the maximum number of connections

Codeforces Round #810 (Div.2) A-C

An open source OA office automation system

单片机多级菜单

10000 word parsing MySQL index principle -- InnoDB index structure and reading
随机推荐
Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
Practical new drug R & D project management platform
什么是真正的HTAP?(一)背景篇
Chromedriver download - self use
Comprehensive analysis of ADC noise-01-types of ADC noise and ADC characteristics
LeetCode56. 合并区间
Regular expression foundation sorting
flink中维表Join几种常见方式总结
Shell condition test, judgment statement and operator of shell system learning
【已解决】单点登录成功SSO转发,转发URL中带参数导致报错There was an unexpected error (type=Internal Server Error, status=500)
The first open source MySQL native HTAP database in China will be released soon! Look at the three highlights first, limited to the surrounding areas, waiting for you~
How to get DDL information of an object
Bash: create a function that returns a Boolean value
flink去重(一)flink、flink-sql中常见的去重方案总结
什么是真正的 HTAP ?(二)挑战篇
一体化实时HTAP数据库StoneDB,如何替换MySQL并实现近百倍分析性能的提升
Redison 3.17.5 release, officially recommended redis client
将对象转换为键值对
【StoneDB Class】入门第一课:数据库知识科普
OpenGL shader learning notes: varying variables