当前位置:网站首页>C language: random generated number + insertion sort
C language: random generated number + insertion sort
2022-07-27 07:48:00 【Nianchi ichthyology programming】
#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("========== The sequence before sorting =============\n");
initArr(arr,MAXSIZE);
showArr(arr,MAXSIZE);
printf("========== Insert sorted sequence =============\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)
{
// Insertion sort
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;
}
}
}
边栏推荐
- [golang learning notes 2.0] arrays and slices in golang
- 国内首款开源MySQL原生HTAP数据库即将发布!三大亮点抢先看,限量周边等你来~
- Primary key in MySQL secondary index - MySQL has a large number of same data paging query optimization
- [day42 literature intensive reading] a Bayesian model of perfect head centered velocity during smooth pursuit eye movement
- Confluence vulnerability learning - cve-2021-26084/85, cve-2022-26134 vulnerability recurrence
- 浅谈数据安全
- Framework of electronic mass production project -- basic idea
- MySQL backup strategy
- 模仿大佬制作的宿舍门禁系统(三)
- C#委托的使用案例
猜你喜欢

Understanding and learning of properties class and properties configuration file

帮忙发一份招聘,base全国,有兴趣的可以过来看看

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

Convert objects to key value pairs

Gossip: it's really important to have a rod in your hand and a net on your shoulder. As for how many fish are in the basket?

如何在电脑端登陆多个微信

【已解决】新版Pycharm(2022)连接服务器进行上传文件报错“Command rsync is not found in PATH”,无法同步文件

【小程序】如何获取微信小程序代码上传密钥?

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~

MySQL backup strategy
随机推荐
10000 word parsing MySQL index principle -- InnoDB index structure and reading
MCU multi-level menu
Installation and use of apifox
yhb_ sysbench
Confluence vulnerability learning - cve-2021-26084/85, cve-2022-26134 vulnerability recurrence
[golang learning notes 2.0] arrays and slices in golang
Am I delayed by the code... Unfortunately, I became a programmer
slf4j如何进行logback配置呢?
Flynk de duplication (2) solve the hot issues in the process of flynk and flynk SQL de duplication
【万字长文】吃透负载均衡,和阿里大牛的技术面谈
【Golang】golang开发微信公众号网页授权功能
Day111.尚医通:集成NUXT框架、前台页面首页数据、医院详情页
MySQL table name area in Linux is not case sensitive
npm的使用
容器内使用sudo报错bash: sudo: command not found解决
[golang learning notes 2.1] sorting and searching in arrays in golang
linux中mysql表名区不区分大小写
JS regular expression implementation adds a comma to every three digits
C# 事件用法案例 订阅事件+=
【小程序】如何获取微信小程序代码上传密钥?