I am writing a c++ program to sort an array and I came to know that std::sort
is directly available within c++ as part of the algorithm header library for c++.
What kind of sort technique and algorithm is used to implement inherent sort? What is the time complexity of the sort function used?
The exemplar code is like :
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
int main()
{
std::array<int, 10> s = {5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
`enter code here` // sort using the default operator<
std::sort(s.begin(), s.end());
for (auto a : s) {
std::cout << a << " ";
}
std::cout << '\n';
// sort using a standard library compare function object
std::sort(s.begin(), s.end(), std::greater<int>());
for (auto a : s) {
std::cout << a << " ";
}
Aucun commentaire:
Enregistrer un commentaire