直接插入排序。。。
2010-07-30 09:36
267 查看
#include <cstdlib> #include <iostream> #include <ctime> #include <algorithm> using namespace std; const int MAX = 500; const int COUNT = 10; void display(int value[], int count) { for(int i=0; i<count; i++) cout << value[i] << " "; cout << endl; } void directInsertSort(int value[], int count) { int temp; for(int i=1; i<count; i++) { temp = value[i]; int j = i; for(; j>0; j--) { if(temp < value[j - 1]) value[j] = value[j - 1]; else break; } value[j] = temp; } } int main(int argc, char *argv[]) { int value[COUNT]; srand((unsigned)time(NULL)); for(int i=0; i<COUNT; i++) value[i] = rand() % MAX; cout << "raw data is: " << endl; display(value, COUNT); directInsertSort(value, COUNT); cout << "after direct insert sort: " << endl; display(value, COUNT); system("PAUSE"); return EXIT_SUCCESS; }
相关文章推荐
- 直接插入排序
- python数据结构之直接插入排序
- 直接插入排序
- 直接插入排序
- 排序3:直接插入排序
- 第十五周内部排序(2)项目1---(1)直接插入排序
- 直接插入排序
- IOS- 快速排序,冒泡排序,直接插入排序和折半插入排序,希尔排序,堆排序,直接选择排序
- 直接插入排序
- java直接插入排序(扑克排序)
- 数据结构——排序——直接插入排序和折半插入排序算法
- 排序详解:直接插入排序
- c++学习之--排序2-直接插入排序
- 直接插入排序
- 链表排序-直接插入排序
- 1062-直接插入排序
- 笔试之排序-直接插入排序、冒泡排序、快速排序
- 插入排序之直接插入排序
- 第十五周项目1(1)-验证算法(直接插入排序)
- 排序算法之直接插入排序