我的 shell 排序如下所示:
template<class T>
void shellSort(T *begin, T *end) {
int shell = 1;
while (shell < (begin - end) / 3) shell = shell * 3 + 1;
while (shell > 0) {
for (auto index = shell; index < end; index++) {
for (auto insertion = index; insertion >= shell && *(insertion - shell) > *(insertion); insertion -= shell) {
swap(*(insertion - shell), *(insertion));
}
}
shell = shell / 3;
}
}
漂亮的磨坊。我遇到的问题是在这一行:
for (auto index = shell; index < end; index++)
由于shell
is anint
但end
is anint *
它不知道如何进行比较。我该如何解决这个问题?