当前位置:网站首页>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;
}
}
}
边栏推荐
- ARP broadcasting practice cases
- Hu related configuration
- flink中维表Join几种常见方式总结
- Do me a favor ~ don't pay attention, don't log in, a questionnaire in less than a minute
- The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly 100 times the improvement of analysis performance
- Comprehensive analysis of ADC noise-01-types of ADC noise and ADC characteristics
- Oracle composite query
- Solidity智能合约开发 — 3.3-solidity语法控制结构
- RestTemplate 连接池配置
- Multi condition query of when
猜你喜欢

MCU multi-level menu

我是不是被代码给耽误了……不幸沦为一名程序员……

安装tensorflow

Panabit SNMP配置

Framework of electronic mass production project -- basic idea

The DrawImage method calls the solution of not displaying pictures for the first time

连接MySQL时报错:Public Key Retrieval is not allowed 【解决方法】

【pytorch】ResNet18、ResNet20、ResNet34、ResNet50网络结构与实现

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

防止Cookie修改id欺骗登录
随机推荐
电子量产项目框架--基本思想
How to get DDL information of an object
flink去重(一)flink、flink-sql中常见的去重方案总结
Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk
sql语句批量更新 时间减去1天
【已解决】新版Pycharm(2022)连接服务器进行上传文件报错“Command rsync is not found in PATH”,无法同步文件
DASCTF2022.07赋能赛密码wp
Okaleido生态核心权益OKA,尽在聚变Mining模式
DEMO:PA30 银行国家码默认CN 增强
Regular and sed exercises
C# 中的转译字符'/b'
slf4j如何进行logback配置呢?
Plato Farm有望通过Elephant Swap,进一步向外拓展生态
Installation and use of apifox
Applet payment management - new payment docking process
单片机多级菜单
JS存取cookie示例
我是不是被代码给耽误了……不幸沦为一名程序员……
What about idea Chinese garbled code
剑指 Offer 58 - I. 翻转单词顺序