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; }
查看全文
相关阅读:
集合框架系列教材 (六)- 其他集合
集合框架系列教材 (五)- ArrayList
集合框架系列教材 (四)- ArrayList
集合框架系列教材 (三)- ArrayList
集合框架系列教材 (二)- ArrayList
集合框架系列教材 (一)- ArrayList
I/O系列教材 (五)- Java的字符流 Reader Writer
I/O系列教材 (四)- 关闭流的方式
I/O系列教材 (三)- Java 字节流 InputStream OutputStream
I/O系列教材 (二)- 什么Java 的流 Stream?
原文地址:https://www.cnblogs.com/seebro/p/2476549.html
最新文章
异常处理能捕获拦截器intercepter里面抛出的异常吗?
拦截器Intercepter
springmvc全局异常处理
meth breakpoints may dramatically slow down debugging
Saxon cannot write a DOMResult unless saxon9-dom.jar is on the classpath
Error creating bean with name 'documentationPluginsBootstrapper'
nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.json.Json
idea设置freemark自动更新
趣谈分布式系统
分布式事务详解
热门文章
html img图片模糊效果
html img图片模糊效果
几款浏览器兼容性测试工具
几款浏览器兼容性测试工具
HTML的position详解
HTML的position详解
vue @click.native
vue @click.native
17张图带你解析红黑树的原理!保证你能看懂!
17张图带你解析红黑树的原理!保证你能看懂!
Copyright © 2011-2022 走看看