-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSorting.cpp
More file actions
57 lines (34 loc) · 1.07 KB
/
Sorting.cpp
File metadata and controls
57 lines (34 loc) · 1.07 KB
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
55
56
57
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
// Sorting
// Link: https://youtu.be/x0uUKWJzSO4
// Title: Sorting in C++
// Creator: The Cherno
// sort si può utilizzare con qualsiasi tipo, string, int, char...
int main() {
setlocale(LC_ALL, "italian");
vector <int> valori = {4, 10, 3, 2, 5, 1};
sort(valori.begin(), valori.end()); // funziona con STD::VECTOR, STD::ARRAY
// "non funzion" con array normali
// in questo modo ordiniamo da 0-n
sort(valori.begin(), valori.end(), [](int a, int b) { // è uguale a ^^^
return a < b;
});
sort(valori.begin(), valori.end(), greater<int>()); // in questo modo da n-0
sort(valori.begin(), valori.end(), [](int a, int b) { // è uguale a ^^^
return a > b;
});
sort(valori.begin(), valori.end(), [](int a, int b) {
if (a == 1)
return false; // dopo (ultimo)
if (b == 1)
return true; // prima (prima)
return a > b;
});
for (int indice : valori)
cout << indice << endl;
cin.get();
}