zoukankan
html css js c++ java
shell sort
#include <iostream> template <class elem> void swap(elem a[], int p1, int p2) { elem tmp = a[p1]; a[p1] = a[p2]; a[p2] = tmp; } template <class elem> void print(elem a[], int length) { for (int i = 0; i < length; i++) std::cout << a[i] << ' '; std::cout << std::endl; } template <class elem> void insert_sort(elem a[], int length, int increment) { for (int i = increment; i < length; i += increment) for (int j = i; j >= increment; j -= increment) if (a[j] < a[j-increment]) swap(a, j, j - increment); } template <class elem> void shell_sort(elem a[], int length) { for (int i = length/2; i > 2; i/= 2) for (int j = 0; j < i; j++) insert_sort(&a[j], length - j, i); insert_sort(a, length, 1); } int main(void) { int a[] = {42, 20, 17, 13, 28, 14, 23, 15}; print(a, 8); shell_sort(a, 8); print(a, 8); system("pause"); return 0; }
查看全文
相关阅读:
table 如何不越过父级div
sqlite3_column_type 与 SQLITE_NULL的区别
lua 协程的理解
linux 信号
linux 查看文件夹大小
linux 僵屍进程
软件架构的理解
jquery正则表达式
linux C遍历目录下文件
linux 进程间同步互斥
原文地址:https://www.cnblogs.com/seebro/p/2476549.html
最新文章
【自动化测试】Selenium 下载文件
【自动化测试】Selenium 2.0 学习笔记
【学习】菜鸟的心路历程
【Python】类和对象、继承、使用文件、存储、异常、标准库(不懂)
【Python】控制流语句、函数、模块、数据结构
【Python】菜鸟的基本课程继续中
【Python】入门 list有些不懂
ci制作登陆+验证码
提高搜索引擎的的效率的几个方法
snoopy的使用
热门文章
网页采集+pdo入库
高逼格的画图:VIM原来可以这样玩
Linux bashrc和profile的用途和区别
CoreOS 835.12.0 稳定版安装
Centos6下DRBD的安装配置
LVS负载均衡集群服务搭建详解(二)
总结六条对我们学习Linux系统有用的忠告
Git常用命令总结(超实用)
在FreeBSD上安装Bugzilla
LVS负载均衡集群服务搭建详解(一)
Copyright © 2011-2022 走看看