I found two forms of sort() in C++:
1) sort(begin, end);
2) XXX.sort();
One can be used directly without an object, and one is working with an object.
Is that all? What’s the differences between these two sort()? They are from the same library or not? Is the second a method of XXX?
Can I use it like this
vector<int> myvector
myvector.sort();
or
list<int> mylist;
mylist.sort();
std::sortis a function template that works with any pair of random-access iterators. Consequently, the algorithm implemented bystd::sortis tailored (optimized) for random access. Most of the time it is going to be some flavor of quick-sort.std::list::sortis a dedicated list-oriented version of sort.std::listis a container that does not support [efficient] random access, which means that you can’t usestd::sortwith it. This creates the need for a dedicated sorting algorithm. Most of the time it will be implemented as some flavor of merge-sort.