-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sets.cpp
63 lines (47 loc) · 1.11 KB
/
Sets.cpp
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
#include "stdafx.h"
#include <iostream>
#include <set>
#include <string>
using namespace std;
class Test {
int id;
string name;
public:
Test() : id(0), name("") {
}
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;
}
};
int _main9(int argc, _TCHAR* argv[]) {
set<int> numbers;
numbers.insert(50);
numbers.insert(10);
numbers.insert(30);
numbers.insert(30);
numbers.insert(20);
for(set<int>::iterator it = numbers.begin(); it != numbers.end(); it++) {
cout << *it << endl;
}
set<int>::iterator itFind = numbers.find(30);
if(itFind != numbers.end()) {
cout << "Found: " << *itFind << endl;
}
if(numbers.count(30)) {
cout << "Number found." << endl;
}
set<Test> tests;
tests.insert(Test(10, "Mike"));
tests.insert(Test(30, "Joe"));
tests.insert(Test(333, "Joe"));
tests.insert(Test(20, "Sue"));
for(set<Test>::iterator it = tests.begin(); it != tests.end(); it++) {
it->print();
}
return 0;
}