直接插入排序(C++模版技术实现)
2011-05-28 00:09
489 查看
下面代码仅供本人复习数据结构所用,实用性N低,各位飘过吧~~哈哈:>
// // C++ 模版技术实现直接插入排序. // #include <cstdlib> #include <cstring> #include <iostream> template <typename T> void insertionSort(T *array, const size_t count) { T temp; for (size_t i = 1, j; i < count; ++i) { for (j = i, temp = array[j]; 0 < j && temp < array[j - 1]; --j) { array[j] = array[j - 1]; } array[j] = temp; } } // // 测试 // int main(void) { char szTest[] = "Insertion sort algorithm test case !"; int iarrTest[] = {23, 12, 2, 123, 72, 35, 49, 51, 83, 94, 65}; const size_t INT_ARR_SIZE = sizeof(iarrTest) / sizeof(iarrTest[0]); insertionSort(szTest, strlen(szTest)); insertionSort(iarrTest, INT_ARR_SIZE); std::cout << szTest << std::endl; for (size_t i = 0; i < INT_ARR_SIZE; ++i) { std::cout << iarrTest[i] << " "; } std::cout << std::endl; return EXIT_SUCCESS; }
相关文章推荐
- C++模板实现直接插入排序
- C++模板实现直接插入排序
- c++实现直接插入排序
- C++模板实现直接插入排序
- 插入排序——直接插入排序和希尔排序,C++代码实现
- C++模板实现直接插入排序
- 直接插入排序的C++实现代码
- 直接插入排序的C++实现及随机数组的产生方法
- C++实现常用排序算法(快速排序、冒泡排序、希尔排序、折半插入排序、直接插入排序)
- 直接插入排序、shell 排序、快速排序C++实现
- 数据结构复习:直接插入排序与二分插入排序的C++实现
- 数据结构图文解析之:直接插入排序及其优化(二分插入排序)解析及C++实现
- 用C++实现直接插入排序
- 直接插入排序(C++实现)
- C++实现直接插入排序
- c++实现数据结构中的各种排序方法:直接插入、选择,归并、冒泡、快速、堆排序、shell排序
- c++实现插入排序模版
- c++ 模板实现 -- 直接插入排序和归并排序
- C++实现直接插入排序,折半插入排序,希尔排序,冒泡排序,简单选择排序,快速排序,堆排序
- java实现直接插入排序