希尔排序(C++版)

#include <iostream>

using namespace std;

/** Shell Sort 
 *
 * Key:
 * * increment
 * * insertSort(:increment)
 *
 */     

template <typename T>
void insertSort_shell(T* a, int start, int incre) {
    T tm;
   n=sizeof(a)/sizeof(T)
for(int i = start+incre; i < n; i = i+incre) { /// how many to tm = a[i]; int j = i - incre; while(a[j] > tm && j >=0){ a[j+incre] = a[j]; j = j - incre; } a[j+incre] = tm; } } template <typename T> void shellSort(T* a, int n) { int incre = n/2; while (incre >=1) { for(int i = 0; i < incre; i++) { insertSort_shell(a, i, incre); } incre = incre / 2; } }

 

posted on 2016-02-21 21:57  qmzp  阅读(281)  评论(0编辑  收藏  举报

导航