地精排序-Gnome Sort
2016-11-25 19:03
393 查看
1.if i==0,we should straightly i++;
2.else if it’s ordered until a[i],we should i++ to skip
3.if it is unordered until a[i],we should swap,and then Roll back to i-1 to rejudge
来自:
http://www.cnblogs.com/kkun/archive/2011/11/23/2260296.html
http://blog.csdn.net/winark/article/details/5918944
2.else if it’s ordered until a[i],we should i++ to skip
3.if it is unordered until a[i],we should swap,and then Roll back to i-1 to rejudge
c语言
#include<stdio.h> void gnomesort(int a[],int n) { int i = 0; while (i < n) if (i == 0 || a[i-1] <= a[i]) i++; else { int tmp = a[i]; a[i] = a[i-1]; a[--i] = tmp; } } int main() { int a[5]= {7,4,1,3,2}; gnomesort(a,5); for(int i=0; i<5; i++)printf("%d ",a[i]); }
来自:
http://www.cnblogs.com/kkun/archive/2011/11/23/2260296.html
http://blog.csdn.net/winark/article/details/5918944
相关文章推荐
- 地精排序Gnome Sort ----(排序算法十)
- 地精排序(Gnome Sort) 算法
- 地精排序 Gnome Sort
- 地精排序Gnome Sort
- java排序算法_008地精排序(Gnome Sort)
- 地精排序(Gnome Sort) 最简单的排序算法
- 再探地精排序GnomeSort
- 数据结构杂谈(二)简单有趣的地精排序Gnome sort
- 地精排序Gnome Sort ----(排序算法十)
- 经典排序算法 - 地精排序Gnome Sort
- Collections的sort方法 排序
- Lucene使用SortField对多个字段进行排序
- awk 之 asort 与 asorti 数组排序区别及演示
- 九度 OJ 题目1061:成绩排序(重载<,利用sort())
- PHP中的排序函数sort、asort、rsort、krsort、ksort区别分析
- Java1.7通过collections类的sort方法对ArrayList进行排序无效的解决办法。
- 数组Array的排序sort
- 算法第三次作业(1. 排序。对文件 largeW.txt(下载链接)中的数据,编程实现冒泡排序(方法名:bubbleSort) 与 归并排序(mergeSort),把排序后的结果分别保存到largeW
- 堆排序(Heap Sort)的C语言实现
- lintcode :sort letters by case字符大小写排序