当前位置:网站首页>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 language implementation of guessing numbers Games project practice (based on srand function, rand function, switch statement, while loop, if condition criterion, etc.)
- Closed hash and open hash resolve hash conflicts
- 如何在电脑端登陆多个微信
- [resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL
- 小程序支付管理-新版支付对接流程
- The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly 100 times the improvement of analysis performance
- shell循环练习
- Framework of electronic mass production project -- basic idea
- [day42 literature intensive reading] a Bayesian model of perfect head centered velocity during smooth pursuit eye movement
- Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk
猜你喜欢

Okaleido ecological core equity Oka, all in fusion mining mode

Temperature and humidity measurement and display device based on Arduino

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

单片机多级菜单

Leetcode54. 螺旋矩阵

MCU multi-level menu
![Error when connecting to MySQL: public key retrieval is not allowed [solution]](/img/b3/41523d44924ec203e40453bace6627.png)
Error when connecting to MySQL: public key retrieval is not allowed [solution]

Comprehensive analysis of ADC noise-02-adc noise measurement method and related parameters

DEMO SUBMIT 某程序并获取该程序ALV数据

Day111.尚医通:集成NUXT框架、前台页面首页数据、医院详情页
随机推荐
剑指 Offer 58 - I. 翻转单词顺序
杂谈:手里有竿儿,肩上有网,至于背篓里有多少鱼真的重要吗?
Docker install MySQL 8.0.28
[resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL
npm的使用
Systematic explanation of unit testing: mockito
【Golang】golang开发微信公众号网页授权功能
Clickhouse notes 1 | introduction, features | installation and use based on centos7 system | common data types | mergetree table engine | SQL operation
Confluence vulnerability learning - cve-2021-26084/85, cve-2022-26134 vulnerability recurrence
小程序支付管理-新版支付对接流程
C# 中的转译字符'/b'
Shell enterprise interview exercise
Redison 3.17.5 release, officially recommended redis client
Redisson 3.17.5 发布,官方推荐的 Redis 客户端
Abstract factory pattern
Flink1.14 SQL basic syntax (I) detailed explanation of Flink SQL table query
存储过程与函数
LeetCode56. 合并区间
ARP broadcasting practice cases
C language implementation of guessing numbers Games project practice (based on srand function, rand function, switch statement, while loop, if condition criterion, etc.)