os_sort |
A helper algorithm for sort()
. Sorts all elements in the container c into ascending
order. The first version uses operator< to
compare elements, whereas the second version uses the binary function compare
.
#include <ospace/helper/helpalgo.h>
template< class Container >
void os_sort( Container& c )
template< class Container, class Compare >
void os_sort( Container& c, Compare compare )
#include <iostream>
#include <vector>
#include <ospace/helper.h>
int numbers[ 6 ] = { 1, 50, -10, 11, 42, 19 };
void
main()
{
vector< int > v( numbers, numbers + 6 );
os_sort( v );
for ( size_t i = 0; i < v.size(); ++i )
cout << v[ i ] << ` `;
cout << "\n";
}
-10 1 11 19 42 50
#include <iostream>
#include <functional>
#include <vector>
#include <ospace/helper.h>
int numbers[] = { 1, 50, -10, 11, 42, 19 };
void
main()
{
vector< int > v( numbers, numbers + 6 );
os_sort( v, greater< int >() );
for ( size_t i = 0; i < v.size(); ++i )
cout << v[ i ] << ` `;
cout << "\n";
}
50 42 19 11 1 -10
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.