当前位置:网站首页>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;
}
}
边栏推荐
- Codeforces Round #810 (Div.2) A-C
- Usage scenarios for automated testing
- Flink principle (I) TTL management and fault tolerance mechanism of state
- Day111.尚医通:集成NUXT框架、前台页面首页数据、医院详情页
- 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?
- Comprehensive analysis of ADC noise-01-types of ADC noise and ADC characteristics
- 大家节日快乐哈
- 杂谈:把肉都烂在锅里就是保障学生权益了?
- 鲁迅:我不记得说没说过,要不你自己查!
- 为啥国内大厂都把云计算当成香饽饽,这个万亿市场你真的了解吗
猜你喜欢

STM32_ Find the cause of entering hardfault_ Handler's function

Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
![[day42 literature intensive reading] a Bayesian model of perfect head centered velocity during smooth pursuit eye movement](/img/28/979dceac1454a3e53409a4feb20320.png)
[day42 literature intensive reading] a Bayesian model of perfect head centered velocity during smooth pursuit eye movement

An open source OA office automation system

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

Can Linux install sqlserver

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

Framework of electronic mass production project -- basic idea

Panabit SNMP configuration

ADC噪声全面分析 -02- ADC 噪声测量方法和相关参数
随机推荐
【小程序】如何获取微信小程序代码上传密钥?
安装tensorflow
容器内使用sudo报错bash: sudo: command not found解决
【飞控开发基础教程4】疯壳·开源编队无人机-串口(光流数据获取)
kalibr标定realsenseD435i --多相机标定
IDEA中文乱码怎么办
正则 和 sed 练习
MySQL table name area in Linux is not case sensitive
Abstract factory pattern
C language implementation of guessing numbers Games project practice (based on srand function, rand function, switch statement, while loop, if condition criterion, etc.)
shell循环练习
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~
Temperature and humidity measurement and display device based on Arduino
shell 函数和数组练习
HU相关配置
The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly 100 times the improvement of analysis performance
yhb_ sysbench
Redison 3.17.5 release, officially recommended redis client
C language programming | program compilation and preprocessing
opengl-shader学习笔记:varying变量