-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSorting.cpp
More file actions
47 lines (35 loc) · 853 Bytes
/
Sorting.cpp
File metadata and controls
47 lines (35 loc) · 853 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 "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
class Test {
int id;
string name;
public:
Test(int id, string name) : id(id), name(name) {
}
void print() const {
cout << id << ": " << name << endl;
}
/*bool operator<(const Test &other) const {
return name < other.name;
}*/
friend bool comp(const Test &a, const Test &b);
};
bool comp(const Test &a, const Test &b) {
return a.name < b.name;
}
int _main11(int argc, _TCHAR* argv[]) {
vector<Test> tests;
tests.push_back(Test(5, "Mike"));
tests.push_back(Test(10, "Sue"));
tests.push_back(Test(7, "Raj"));
tests.push_back(Test(5, "Vicky"));
sort(tests.begin(), tests.end(), comp);
for(int i = 0; i < tests.size(); i++) {
tests[i].print();
}
return 0;
}