希尔排序

    xiaoxiao2021-03-25  74

    希尔排序思想逻辑


    希尔排序代码

    void InsertShellSort(int32_t numList[], int32_t len, int32_t dk) { for (auto i = dk; i < len; i++) { auto preIndex = i - dk; if (numList[i] < numList[preIndex]) { auto tmp = numList[i]; while (tmp < numList[preIndex]) { numList[preIndex + dk] = numList[preIndex]; preIndex -= dk; } numList[preIndex + dk] = tmp; } } } //希尔排序 void ShellSort(int32_t numList[], int32_t len) { auto dk = len / 2; while (dk >= 1) { InsertShellSort(numList, len, dk); dk /= 2; } } void main() { int32_t numList[] = {70,30,40,10,80,20,90,100,75,60,45 }; int32_t count = sizeof(numList) / sizeof(numList[0]); ShellSort(numList, count); for (auto num : numList) { std::cout << num << " "; } std::cout << std::endl; }

    返回排序算法分析总结

    转载请注明原文地址: https://ju.6miu.com/read-38193.html

    最新回复(0)