-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortofSorting.cpp
More file actions
67 lines (41 loc) · 1.33 KB
/
Copy pathSortofSorting.cpp
File metadata and controls
67 lines (41 loc) · 1.33 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
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;
//compare the strings (student)
bool compare (string first, string second){
if((first[0] == second[0]) && (first[1] == second[1])){
return 0; // will not swap if the first two char of the string are the same (order wont change)
}
else
return first < second; // will swap
}
int main(void){
ios::sync_with_stdio(false); cin.tie(0);
int setnum;
vector<string> names;
string student;
cin >> setnum;
cin.ignore();
while(setnum != 0){
names.clear(); // clear the array after one cycle
//To input data
for(int i=0; i<setnum; i++){
cin >> student;
names.push_back(student);
}
stable_sort(names.begin(), names.end(), compare); // compare is a function that is called
cout << endl;
//To display data
for(auto v:names){
cout << v<<endl;
}
cout << endl;
cin >> setnum;
}
return 0;
}
// //To sort data in increasing order
// sort(names.begin(), names.end()); //begin means the 1st element till end, last element
// adding + 3 means it will not sort the first 3 elements
//stable_sort(names.begin() + 3, names.end());
// adding + 1 means it will only sort the first element
//partial_sort(names.begin(), names.begin() + 1, names.end());