-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortfunction.cpp
More file actions
56 lines (36 loc) · 830 Bytes
/
sortfunction.cpp
File metadata and controls
56 lines (36 loc) · 830 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
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<algorithm>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<vector<int>> vect{{3,6},{17,15},{13,15},{16,12},{9,1},{2,7},{10,19}};
int n=vect.size();
cout<< " Original matrix "<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<2;j++)
cout<< vect[i][j] << " ";
cout<<endl;
}
sort(vect.begin(),vect.end());
cout<< "Sort by x axis "<<endl;
for(int i=0; i<n;i++){
for(int j=0; j<2;j++)
cout<< vect[i][j]<<" ";
cout<<endl;
}
// " swap"
for(int i=0; i<n;i++)
swap(vect[i][0],vect[i][1]);
cout<< " sort by y axis" << endl;
sort(vect.begin(),vect.end());
for(int i=0;i<n;i++)
swap(vect[i][0],vect[i][1]);
/// Display the sorted version by y axis
for(int i=0; i<n; i++){
for(int j=0;j<2; j++)
cout<<vect[i][j] << " ";
cout<<endl;
}
return 0;
}