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; }
查看全文
相关阅读:
state estimation for robotics-1
Linux命令----用户目录、路径
Linux命令----系统目录结构
Linux命令----shell
socket php
深入浅出讲解:php的socket通信 转
phpstorm配置sftp自动上传
linux下xdebug的安装和配置方法
xdebug安装
swoole 客户端和服务端不断通信
原文地址:https://www.cnblogs.com/seebro/p/2476549.html
最新文章
#Leetcode# 53. Maximum Subarray
#Leetcode# 75. Sort Colors
#Leetcode# 4. Median of Two Sorted Arrays
#Leetcode# 342. Power of Four
#Leetcode# 344. Reverse String
#Leetcode# 292. Nim Game
二分 by zzt
#Leetcode# 67. Add Binary
Linux——chmod、chown
linux——nano
热门文章
linux--ps tar命令
1.SJ-SLAM-14
PPJQR-GKK-2深度学习及应用
激光SLAM
2.15交互输入自动化
2.14拼写检查与词典操作
2.13 批量重命名和移动
2.12根据扩展名切分文件名
2.10临时文件命名与随机数2.11
PYTHON-1
Copyright © 2011-2022 走看看