摘要:
归并排序理论上时间复杂度只有O(NlogN),但是其中存在过多临时内存分配和copy操作而不适用于内存排序,却是外部排序的基本思路。下面是我的实现:#include<iostream>#include<algorithm>#include<cstring>using namespace std;int g=0;/*a,b is input array * c is output array * size of c is na+nb */template<typename T>void merge(T a[],int na,T b[],int nb 阅读全文
摘要:
希尔排序的时间复杂度在O(N)到O(N2)之间,在大量数据排序中实践性能超过堆排序。特点是算法简单但是分析复杂。下面是实现:/* * a[] is an array to be sorted * n1 is the T array length * inc[] is the array to indecate the increasement * n2 is the inc array length */template<typename T>void shellsort(T a[],int n1,int inc[],int n2){ for(int i=0;i<n2;++i 阅读全文