Gnome sort: Sorting by Exchanging
来源:互联网 发布:网络女主播喝醉 编辑:程序博客网 时间:2024/05/24 04:07
Gnome sort:地精排序
Animation
Visualisation of Gnome sort
Complexity
Java program
/** * User: >_< * Date: 11/12/15 * Time: 10:41 AM */public class GnomeSort { public static void gnome_sort(int[] input){ int pos = 1; while (pos < input.length){ if(input[pos] >= input[pos-1]) pos++; else{ int temp = input[pos]; input[pos] = input[pos-1]; input[pos-1] = temp; if(pos > 1) pos--; } } } public static void main(String[] args) { //Prepare the data int[] number = {503,87,512,61,908,170,897,275,653,426,154,509,612,677,765,703}; //Output unsorted Keys System.out.println("Unsorted Ks:"); for(int i=1; i<=number.length; i++){ System.out.println(i+":"+number[i-1]); } System.out.println(); //Kernel of the Algorithm! gnome_sort(number); //Output sorted Keys System.out.println("Sorted Ks:"); for(int i=1; i<=number.length; i++){ System.out.println(i+":"+number[i-1]); } }}
Outputs
Unsorted Ks:1:5032:873:5124:615:9086:1707:8978:2759:65310:42611:15412:50913:61214:67715:76516:703Sorted Ks:1:612:873:1544:1705:2756:4267:5038:5099:51210:61211:65312:67713:70314:76515:89716:908
Reference
https://en.wikipedia.org/wiki/Gnome_sort
0 0
- Gnome sort: Sorting by Exchanging
- Optimized Gnome sort: Sorting by Exchanging
- Comb sort: Sorting by Exchanging
- Stooge sort: Sorting by Exchanging
- Internal Sorting: Radix sort: Sorting by Exchanging
- Internal Sorting: Bubble sort: Sorting by Exchanging
- Odd-even sort: Sorting by Exchanging
- Internal Sorting: Radix exchange sort: Sorting by Exchanging
- Internal Sorting: Merge exchange sort: Sorting by Exchanging
- Internal Sorting: Cocktail-shaker sort: Sorting by Exchanging
- Bogosort: Sorting by Exchanging
- Bozosort: Sorting by Exchanging
- Internal Sorting: Quicksort-2: Sorting by Exchanging
- Internal Sorting: Quicksort-1:Sorting by Exchanging
- Internal Sorting: Radix List Sort: Sorting by Distribution
- Internal Sorting: List Merge Sort: Sorting by Merging
- Internal Sorting: Straight Two-way Merge Sort: Sorting by Merging
- Internal Sorting: Natural Two-way Merge Sort: Sorting by Merging
- ios开发 系统提示音的使用
- 警告: 程序集绑定日志记录被关闭。
- SQLiteException: Can't upgrade read-only database
- 面向领域设计不流行的原因猜测
- 获取存储过程返回值及代码中获取返回值
- Gnome sort: Sorting by Exchanging
- Spring Test+JUnit完美组合
- Java学习笔记(十七)泛型及并发线程
- Http——HTTPS和SSL/TLS协议
- 如何在地图上画曲线轨迹(贝塞尔曲线)
- this super static abstract final
- loadrunner 参数化
- c# XML和实体类之间相互转换
- 生成折线图,源代码