每天一个小算法(Shell Sort2)
来源:互联网 发布:淘宝卖家怎么发微淘 编辑:程序博客网 时间:2024/05/01 08:50
希尔排序:
伪代码:
input: an array a of length n with array elements numbered 0 to n − 1inc ← round(n/2)while inc > 0 do: for i = inc .. n − 1 do: temp ← a[i] j ← i while j ≥ inc and a[j − inc] > temp do: a[j] ← a[j − inc] j ← j − inc a[j] ← temp inc ← round(inc / 2)
C语言实现:
#include <stdio.h>#include <stdlib.h>#define LEN 10 int main(){ int i, j, temp; int gap = 0; int a[] = {10,9,8,7,6,5,4,3,2,1}; while (gap<=LEN) { gap = gap * 3 + 1; } while (gap > 0) { for ( i = gap; i < LEN; i++ ) { j = i - gap; temp = a[i]; while (( j >= 0 ) && ( a[j] > temp )) { a[j + gap] = a[j]; j = j - gap; } a[j+gap] = temp; } gap = ( gap - 1 ) / 3; } for(i=0;i<LEN;i++) { printf("%d\n",a[i]); } }
0 0
- 每天一个小算法(Shell Sort2)
- 每天一个小算法(Shell Sort1)
- 每天一个小算法(Shell Sort3)
- 每天一个小算法(Shell Sort4)
- 每天一个小算法(Shell sort5)
- 每天一个小算法之Shell排序(希尔排序)
- 每天一个小算法(insertion sort3)
- 每天一个小算法(matlab armijo)
- 每天一个小算法(matlab armijo)
- 每天一个小算法(Heapsort)
- 每天一个小算法(Heapsort)
- 每天一个小算法(Heapsort)
- 每天一个小算法(Heapsort)
- 每天一个小算法(Heapsort)
- 每天一个小算法 --- 排序
- 每天一个面向对象陷阱,一个算法,一个小看法
- 每天一个小算法之 选择排序算法
- 每天一个shell命令(更新中)
- UC测试实习生笔试面试
- cocos2dx[3.2]——文件操作FileUtils
- URAL - 1297 Palindrome(后缀数组求最长回文子串)
- Leetcode--atoi
- Linux用户管理命令(第二版)
- 每天一个小算法(Shell Sort2)
- STL deque
- 数据库主键和外键
- 读“为什么c程序要从main函数开始执行”
- 2014美团网校园招聘研发类笔试(哈尔滨站)
- hdu2091空心三角形
- 国庆节前夕的夜晚
- POJ 3160 强联通缩点+dp
- 动态创建用户对象对象的方法