top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Which sorting algorithm std::sort() function uses behind the scenes in C++?

0 votes
407 views
Which sorting algorithm std::sort() function uses behind the scenes in C++?
posted Feb 17, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

it uses quick sort algorithm which have complexity O(n log n). The introduction of hybrid algorithms such as introsort allowed both fast average performance and optimal worst-case performance. Different compiler uses different algorithms.
Reference : https://en.wikipedia.org/wiki/Sort_(C%2B%2B)#Complexity_and_implementations (Inside Complexity and Implementation Paragraph)

answer Feb 26, 2016 by Shivam Kumar Pandey
Similar Questions
0 votes

The problem is that some of the fields contain commas, but they are inside double quotes.

Example:

sort -t, -k1,1 -k3,3 -k2,2 SomeFile.csv > OutputFile.csv

A line could look something like this:
This is the first field,"This is, well, the second field",The third field could look like this

That line has three fields:
1: This is the first field
2: "This is, well, the second field"
3: The third field could look like this

But sort consider it to have five fields:
1: This is the first field
2: "This is
3: well
4: the second field
5: The third field could look like this

How would you solve this?

...