添加插入、堆、归并、希尔、计数、桶、基数排序算法及其实现

This commit is contained in:
huihut
2018-04-16 13:30:03 +08:00
parent 90ef525b75
commit 3a0079899d
11 changed files with 380 additions and 21 deletions

15
Algorithm/ShellSort.h Normal file
View File

@@ -0,0 +1,15 @@
template<typename T>
void shell_sort(T array[], int length) {
int h = 1;
while (h < length / 3) {
h = 3 * h + 1;
}
while (h >= 1) {
for (int i = h; i < length; i++) {
for (int j = i; j >= h && array[j] < array[j - h]; j -= h) {
std::swap(array[j], array[j - h]);
}
}
h = h / 3;
}
}