当前位置:网站首页>Shell Sort
Shell Sort
2022-06-22 20:01:00 【Just one word】
Brief book tutorial
https://www.jianshu.com/p/d730ae586cf3
Inside gap It's half every time , So finally we can achieve gap = 1, But if only gap = gap/2 Switch to gap = gap/3 You can't , such as gap = 2, Retake gap = gap/3, here gap = 0, Will stop sorting . The following code shows a method
Code :
#include <stdio.h>
void InsertSort(int k[], int n)
{
int i, j, temp;
int gap = n;
for(gap = gap/3 + 1;gap>=1;gap /=3)
{
for( i=gap; i < n; i++ )
{
if( k[i] < k[i-gap] )
{
temp = k[i];
for( j=i-gap; k[j] > temp && j>=0 ; j-=gap )
{
k[j+gap] = k[j];
}
k[j+gap] = temp;
}
}
}
}
int main()
{
int i, a[10] = {
5, 2, 6, 0, 3, 9, 1, 7, 4, 8};
InsertSort(a, 10);
printf(" The result of sorting is :");
for( i=0; i < 10; i++ )
{
printf("%d", a[i]);
}
printf("\n\n");
return 0;
}
边栏推荐
- Human pose estimation
- 散列表(哈希表)
- Upgrade VS2008 crystal report to the corresponding version of vs2013
- [petty bourgeoisie database] break down the concept: data, database, database system, database management system, database technology
- 漫话Redis源码之一百二十二
- 510000 prize pool invites you to join the war! The second Alibaba cloud ECS cloudbuild developer competition is coming
- 树和森林的遍历
- Install some office tools
- 【深入理解TcaplusDB技术】TcaplusDB机型管理
- 堆排序(原理加代码)
猜你喜欢

iVX无代码挑战五秒游戏制作

Openpnp debugging ------ 0816 Feida Tui 0402 taping

如何用银灿IS903主控DIY自己的U盘?(练习BGA焊接的好项目)

编译报错:/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32S against `.rodata‘

0.1-----用AD画PCB的流程

Nrf51822 peripheral learning

2.什么是机械设计?

Modify the antd tree component so that its subclasses are arranged horizontally.

Yarn notes

【深入理解TcaplusDB技术】入门Tcaplus-JDBC开发
随机推荐
MySQL数据库DQL查询操作
哈夫曼树(C语言)
lua--迭代器、模块、元表
1.3----- simple setting of 3D slicing software
vs2008 水晶报表升级到 vs2013对应版本
【深入理解TcaplusDB技术】TcaplusDB 表管理——修改表
【深入理解TcaplusDB技术】TcaplusDB 新增业务集群cluster
Velocity syntax
Tree, forest and transformation of binary tree
【深入理解TcaplusDB技术】TcaplusDB机器如何下架
Geometrical product specifications (GPS) - ISO code system for linear dimensional tolerances
socket的connect函数用法
Array objects can be compared one by one (the original data with the same index and ID will be retained, and the data not in the original array will be added from the default list)
树、森林及二叉树的相互转换
Modify the antd tree component so that its subclasses are arranged horizontally.
C WinForm embedded flash
二叉排序树的查找、插入和删除
AB打包有的Shader没有触发IPreprocessShaders的回调
delegate
510000 prize pool invites you to join the war! The second Alibaba cloud ECS cloudbuild developer competition is coming