What is the time complexity of std::sort() in the C++ standard library?

后端 未结 6 788
暗喜
暗喜 2020-12-23 11:57

What is the complexity of std::sort() in the C++ Standard Library? Which sort is applied? Is there any rule of applying any particular sorting algorithm there?<

6条回答
  •  执笔经年
    2020-12-23 12:15

    If you mean std::sort():

    This is from C++03 standard, section 25.3. The performance guarantee:

    template
    void sort(RandomAccessIterator first, RandomAccessIterator last);
    
    template void sort(RandomAccessIterator first, RandomAccessIterator last,
        Compare comp);
    

    1 Effects: Sorts the elements in the range [first, last).

    2 Complexity: Approximately N log N (where N == last - first) comparisons on the average.

提交回复
热议问题