Which type of STL container is used for automatic sorting?
What is "automatic sorting"?
Means which container we use for the purpose of sorting?
Do you mean which containers sort implicitly? Like a set or multiset?
http://www.cplusplus.com/reference/set/set/
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include <set>
int main( int argc, const char* argv[] )
{
std::set<int> my_set;
for( int i = 10; i > 0; --i )
my_set.insert( i );
for( const auto &j : my_set )
std::cout << j << " ";
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 |
Last edited on
AFAIK, there is non.
But you can use std::sort() from <algorithm> ??
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
#include <algorithm>
#include <array>
int main()
{
std::array<int, 8> arr { 23, 353, 64, 876, 44, 99, 100, 34 };
std::cout << "Unsorted: ";
for( auto& i : arr ) { std::cout << i << " "; }
std::sort( arr.begin(), arr.end() );
std::cout << "\nSorted: ";
for( auto& i : arr ) { std::cout << i << " "; }
}
|
Last edited on