mirror of
https://github.com/huihut/interview.git
synced 2025-12-18 13:04:38 +03:00
添加插入、堆、归并、希尔、计数、桶、基数排序算法及其实现
This commit is contained in:
15
Algorithm/ShellSort.h
Normal file
15
Algorithm/ShellSort.h
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user