折半插入排序 一个简单示例
2013-03-03 23:39
344 查看
#include <stdio.h> /* * a example of binary insertion sort */ int iList[] = { 0, 99, 3, 8, 123, 4, 6, 2, 9,11 };//init a array for sort and iList[0] is not used void BinaryInsertSort(int iList[], int iLen)//iLen is the length of iList { int low, high; int i, j; int m; for(i = 2; i < iLen; i++) { iList[0] = iList[i];//save the insert number low = 1; high = i - 1;//because the array start from 0 , so it should be i - 1 while(low <= high) { m = (low + high) / 2; if(iList[0] < iList[m]) { high = m - 1; } else { low = m + 1; } } for(j = i; j >= high + 1; --j)//high + 1 is the insert place { iList[j] = iList[j - 1];//backword the array number } iList[high + 1] = iList[0]; } } int main(void) { int i; BinaryInsertSort(iList, 10); for(i = 1; i < 10; i++) { printf(i == 9 ? "%d\n" : "%d, ", iList[i]); } return 0; }
相关文章推荐
- handlersocket使用 第一章 基本语法和一个简单示例
- 一个最简单的div循环流动示例
- 一个简单的Java单例示例谈谈并发
- 使用MyBatis搭建一个访问mysql数据库的简单示例
- 用opengl编写一个简单的画图软件示例代码
- 用perl对文件中的字符串做处理的一个简单的示例
- 一个简单的 iBatis 实现——完整示例
- Asp.net 在网页编写C#代码示例-- 一个简单的web MsSql 命令执行环境
- 一个简单的示例讲解游戏游戏编程原理。附示例源码(转)
- 一个简单的optimizer_trace示例
- 一个简单的Hibernate的示例
- C# 带参数线程的一个简单示例
- 一个简单的struts实现文件上传示例
- 2-路插入排序 一个简单示例
- 冒泡排序 一个简单示例
- 一个简单的CMake示例
- 用Jbuilder8做一个简单的struts示例
- 一个简单的 CORBA/java 示例
- 一个简单的MapReduce示例(多个MapReduce任务处理)
- java泛型之一个简单的泛型示例