#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; } }