当前位置:网站首页>C language: random number + Hill sort
C language: random number + Hill 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 shellSort(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("========== Hill sorted sequence =============\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)
{
// Shell Sort
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;
}
}
边栏推荐
- C# 事件用法案例 订阅事件+=
- Error when connecting to MySQL: public key retrieval is not allowed [solution]
- What other methods are available for MySQL index analysis besides explain
- [resolved] the new version of pychart (2022) connects to the server to upload files and reports an error of "command Rsync is not found in path", and the files cannot be synchronized
- ADC噪声全面分析 -01- ADC噪声的类型以及ADC特性
- Cadence (XI) silk screen printing adjustment and subsequent matters
- 增强:BTE流程简介
- C# 中的转译字符'/b'
- Installation and use of apifox
- Help send a recruitment, base all over the country. If you are interested, you can come and have a look
猜你喜欢
![[resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL](/img/05/41f48160fa7895bc9e4f314ec570c5.png)
[resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL

增强:BTE流程简介

Closed hash and open hash resolve hash conflicts

Am I delayed by the code... Unfortunately, I became a programmer

Bingbing's learning notes: classes and objects (middle)

Demo submit a program and obtain ALV data of the program

ARP broadcasting practice cases

C# 事件用法案例 订阅事件+=

Jjwt generate token

【已解决】单点登录成功SSO转发,转发URL中带参数导致报错There was an unexpected error (type=Internal Server Error, status=500)
随机推荐
[day42 literature intensive reading] a Bayesian model of perfect head centered velocity during smooth pursuit eye movement
小程序消息推送配置 Token校验失败,请检查确认
单片机多级菜单
【Golang】golang开发微信公众号网页授权功能
Lua有状态迭代器
安装tensorflow
一体化实时HTAP数据库StoneDB,如何替换MySQL并实现近百倍分析性能的提升
Day111.尚医通:集成NUXT框架、前台页面首页数据、医院详情页
Regular and sed exercises
剑指 Offer 58 - I. 翻转单词顺序
Zero training platform course-1. SQL injection Foundation
Redison 3.17.5 release, officially recommended redis client
我是不是被代码给耽误了……不幸沦为一名程序员……
Error when connecting to MySQL: public key retrieval is not allowed [solution]
An open source OA office automation system
[resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL
MCU multi-level menu
Record a pit dug by yourself~
Debug:与泛型有关的“无法解析的外部符号”
Docker install MySQL 8.0.28