0

Which sort does this inbuilt sort function follow??

#include<iostream.h> #include<vector.h> #include<algorithm.h> using namespace std; int main() { vector<int>v; int n=10,temp; for(int i=0;i<10;i++) { cin>>temp; v.push_back(temp); } sort(v.begin(),v.end()); for(int i=0;i<10;i++) { cout<<v[i]<<" "; } return 0; }

26th Jan 2017, 2:33 AM
Manikanta Nallamalli (Mittu)
Manikanta Nallamalli (Mittu) - avatar
1 Answer
+ 2
O(N·log(N)), where N = std::distance(first, last) comparisons. (since C++11) http://en.cppreference.com/w/cpp/algorithm/sort "Different implementations use different algorithms. The GNU Standard C++ library, for example, uses a 3-part hybrid sorting algorithm: introsort is performed first (introsort itself being a hybrid of quicksort and heap sort), to a maximum depth given by 2×log2 n, where n is the number of elements, followed by an insertion sort on the result." https://en.wikipedia.org/wiki/Sort_(C%2B%2B)
26th Jan 2017, 3:48 AM
Bou Hani
Bou Hani - avatar