希尔排序
2015-11-10 21:26
134 查看
代码如下:
#include<iostream> using namespace std; void shell_sort(int arr[], int n) { int flag,i,j,length = n; while (length > 1) { length = length / 2; do{ flag = 0; for (i = 0; i < n - length; i++) { j = i + length; if (arr[i]>arr[j]) { int t = arr[i]; arr[i] = arr[j]; arr[j] = t; flag = 1; } } } while (flag == 1); } } void main() { int arr[] = { 3, 5, 4, 6, 2, 8, 7, 9,1,10 }; int n = sizeof(arr) / sizeof(int); for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; shell_sort(arr,n); for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; system("pause"); }
相关文章推荐
- HDU2068 RPG的错排
- 程序路径的操作
- iOS方法类:CGAffineTransform的使用大概
- nfs服务配置
- 块设备驱动1—用内存模拟磁盘
- lightoj--1410--Consistent Verdicts(技巧)
- 一些拿来即用的Web功能网站
- oracle触发器
- UI第一天:UIView及其⼦类
- lightoj--1410--Consistent Verdicts(技巧)
- oracle函数大全
- XCode使用二:Xcode快捷键整理
- [kuangbin带你飞]专题一 简单搜索D - Fliptile(POJ 3279)
- http常见错误
- hdu1160 FatMouse's Speed (求最长严格下降子序列路径)
- iOS 中json数据用法
- POJ 3278-Catch That Cow(bfs)
- 9.5 保护方法调用
- muduo库阅读(19)——日期类
- WinPcap笔记(1):VisualStudio2015配置WinCap