使用c 中的sort()函数对字符串进行排序的最坏情况是什么是什么

What is the worst case time complexity of sorting an array of strings using sort() function in c++?

本文关键字:是什么 排序 最坏 情况 字符串 中的 sort 函数 使用      更新时间:2023-10-16

示例

string input[3]={"Earth","Mars","Mercury"};
sort(input,input+3);

在C 11之前,复杂性平均为N.log(N),最坏的情况复杂性取决于您的标准库实现。对于该语言的以后版本,该标准要求复杂性正好为N.log(N)

来自https://en.cppreference.com/w/cpp/algorithm/sort:

复杂性

o(n·log(n((,其中 N = std::distance(first, last)平均比较。(直到C 11( o(n·log(n((,其中 N = std::distance(first, last)比较。(由于C 11(