Which sorting algorithm is used in GCC?

后端 未结 1 1127
感动是毒
感动是毒 2021-01-04 08:39

From cplusplus.com std::sort complexity is defined:

Complexity

Approximately N*logN comparisons on average (where N is last

1条回答
  •  孤街浪徒
    2021-01-04 08:47

    GCC uses a variation of Musser’s introsort. This guarantees a worst-case running time of O(n log n):

    It begins with quicksort and switches to heapsort when the recursion depth exceeds a level based on … the number of elements being sorted.

    The implementation can be found in the stl_algo.h header in the __introsort_loop function.

    0 讨论(0)
提交回复
热议问题