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;
}
相关推荐
AndrewHZ1 天前
【图像处理基石】有哪些好用的图像去噪算法可以推荐一下么?
图像处理·深度学习·算法·计算机视觉·cv·噪声
雪花desu1 天前
【Hot100-Java中等】:字母异位词分组
java·算法·leetcode·哈希表
Word码1 天前
LeetCode283. 移动零(双指针精讲)
算法·leetcode·职场和发展
xiaoxue..1 天前
二叉搜索树 BST 三板斧:查、插、删的底层逻辑
javascript·数据结构·算法·面试
蒙奇D索大1 天前
【数据结构】排序算法精讲 | 快速排序全解:分治思想、核心步骤与示例演示
数据结构·笔记·学习·考研·算法·排序算法·改行学it
YGGP1 天前
【Golang】LeetCode 55. 跳跃游戏
算法·leetcode
练习时长一年1 天前
Leetcode热题100(跳跃游戏 II)
算法·leetcode·游戏
小白菜又菜1 天前
Leetcode 3432. Count Partitions with Even Sum Difference
算法·leetcode
wuhen_n1 天前
LeetCode -- 15. 三数之和(中等)
前端·javascript·算法·leetcode
sin_hielo1 天前
leetcode 2483
数据结构·算法·leetcode