-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort.cpp
More file actions
47 lines (43 loc) · 897 Bytes
/
Sort.cpp
File metadata and controls
47 lines (43 loc) · 897 Bytes
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
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct point
{
int x, y;
point(int i, int j)
{
x = i;
y = j;
}
};
bool mycomp(point p1, point p2)
{
return p1.y < p2.y;
}
int main()
{
int arr[] = {10, 20, 5, 7};
sort(arr, arr + 4);
for (int x : arr)
cout << x << " ";
cout << "\n";
sort(arr, arr + 4, greater<int>());
for (int x : arr)
cout << x << " ";
cout << "\n";
// vector
vector<int> v = {5, 7, 20, 10};
sort(v.begin(), v.end());
for (int x : v)
cout << x << " ";
cout << "\n";
sort(v.begin(), v.end(), greater<int>());
for (int x : v)
cout << x << " ";
cout << "\n";
// user defined order
point arr2[] = {{3, 10}, {2, 8}, {5, 4}};
sort(arr2, arr2 + 3, mycomp);
for (auto i : arr2)
cout << i.x << " " << i.y << " ";
}