-
Notifications
You must be signed in to change notification settings - Fork 7
/
13_sort.cpp
55 lines (40 loc) · 1.12 KB
/
13_sort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* output
vector: 1 2 3 4 5 6
array: 1 2 3 4 5 6
deque: 6 5 4 3 2 1
*/
#include <range/v3/algorithm/sort.hpp> //specific includes
#include <range/v3/algorithm/for_each.hpp>
namespace rng = ranges::v3;
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <stack>
#include <queue>
#include <array>
#include <iostream>
using namespace std;
auto print = [] (int i) { cout << i << " "; };
int main() {
cout << "vector: ";
vector<int> v { 6, 2, 3, 4, 5, 1 };
rng::sort ( v );
rng::for_each( v, print ); //1 2 3 4 5 6
cout << endl << "array: ";
array<int, 6> a { 6, 2, 3, 4, 5, 1 };
rng::sort ( a );
rng::for_each( a, print );
//well I'm afraid you cannot sort a list...
// list<int> li { 6, 2, 3, 4, 5, 1 };
// auto compare = [](int i, int j) { return i < j; };
// rng::sort ( li, compare );
// rng::for_each( li, print );
cout << endl << "deque: ";
deque<int> d { 6 , 2, 3, 4, 5, 1 };
//sort in reverse
auto rcompare = [](int i, int j) { return i > j; };
rng::sort ( d, rcompare ); // 6 5 4 3 2 1
rng::for_each( d, print );
cout << endl;
}