C语言实现希尔排序

c 复制代码
void ShellSort(int arr[], int n) {//希尔排序--升序
	int i = 0;
	int j = 0;
	int d = n / 2;
	for (d = n / 2;d >= 1;d /= 2) {
		for (i = d;i < n;i++) {
			int tmp = arr[i];
			for (j = i;j >= 0;j -= d) {
				if (tmp < arr[j - d]) {
					arr[j] = arr[j - d];
				}
				else {
					arr[j] = tmp;
					break;
				}
			}
		}
	}
}

int main() {
	int arr[10] = { 3,5,2,9,1,4,8,6,10,7 };
	int n = 10;
	ShellSort(arr, 10);
	for (int i = 0;i < 10;i++) {
		printf("%d ", arr[i]);
	}
	return 0;
}
相关推荐
做cv的小昊6 分钟前
【World Model】π0.5:a Vision-Language-Action Model with Open-World Generalization
人工智能·算法·机器学习·大模型·多模态·vla·世界模型
لا معنى له34 分钟前
World-In-World: World Models in a Closed-Loop World
算法
@yanyu6662 小时前
C编译器安装与第一个C程序
c语言·开发语言
山下梅子酒2252 小时前
洛谷-入门-B2070
c语言
Logic1012 小时前
C语言/数据结构位运算题解:异或XOR找出多任务下载器中的“独特下载速度“——只出现一次的数字
c语言·数据结构·数组·位运算·时间复杂度·算法题·异或性质
Discipline10293 小时前
尼泊尔河流流量:天气驱动的预测与高流量风险
人工智能·算法
XuCoder3 小时前
改一个数,右边全得重算,这题怎么扛住两万次查询
算法
小羊没烦恼!3 小时前
在Scrum中实施敏捷建模
java·开发语言·windows·算法·c#
weixin_307779133 小时前
基于睿擎工业开发平台的预训练视觉模型轻量化适配与低代码部署优化
开发语言·算法
hold?fish:palm4 小时前
45 二叉树的右视图
开发语言·c++·算法