当前位置:网站首页>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 shellSort(int arr[] , int length);
int main()
{
srand((unsigned int)time(NULL));
int arr[MAXSIZE];
printf("==========排序前的序列=============\n");
initArr(arr,MAXSIZE);
showArr(arr,MAXSIZE);
printf("==========希尔排序后的序列=============\n");
shellSort(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 shellSort(int arr[] , int length)
{
//希尔排序
int h = 4;
while(h>=1){
for(int i = h ; i < length ; i++){
for(int j = i ; j >= h && arr[j] < arr[j-h] ; j-=h){
int temp = arr[j];
arr[j] = arr[j-h];
arr[j-h] = temp;
}
}
h /= 2;
}
}
边栏推荐
- Bash: create a function that returns a Boolean value
- 模仿大佬制作的宿舍门禁系统(三)
- glGetUniformLocation,glUniform4f
- Confluence vulnerability learning - cve-2021-26084/85, cve-2022-26134 vulnerability recurrence
- JS regular expression implementation adds a comma to every three digits
- The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly 100 times the improvement of analysis performance
- Plato farm is expected to further expand its ecosystem through elephant swap
- [stonedb class] introductory lesson 1: popular science of database knowledge
- Synchronized lock
- 【飞控开发基础教程4】疯壳·开源编队无人机-串口(光流数据获取)
猜你喜欢

JS regular expression implementation adds a comma to every three digits

杂谈:手里有竿儿,肩上有网,至于背篓里有多少鱼真的重要吗?

ARP broadcasting practice cases

Demo submit a program and obtain ALV data of the program

基于Arduino的温度、湿度测量显示装置

C common function integration-3

flink1.14 sql基础语法(一) flink sql表查询详解

C#winform 窗体事件和委托结合用法

一体化实时HTAP数据库StoneDB,如何替换MySQL并实现近百倍分析性能的提升

C# 中的转译字符'/b'
随机推荐
Comprehensive analysis of ADC noise-02-adc noise measurement method and related parameters
Comprehensive analysis of ADC noise-01-types of ADC noise and ADC characteristics
An open source OA office automation system
yhb_ sysbench
Applet payment management - new payment docking process
sql语句批量更新 时间减去1天
3D激光SLAM:LeGO-LOAM论文解读---摘要
Bingbing's learning notes: classes and objects (middle)
ChromeDriver下载-自用
flink去重(二)解决flink、flink-sql去重过程中的热点问题
Use Amazon dynamodb and Amazon S3 combined with gzip compression to maximize the storage of player data
Install tensorflow
The token verification of applet message push configuration failed. Please check and confirm
Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk
ADC噪声全面分析 -01- ADC噪声的类型以及ADC特性
Multi condition query of when
Convert objects to key value pairs
User unlock sm04 sm12
mysql备份策略
Bash: create a function that returns a Boolean value