-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_stl.cpp
More file actions
49 lines (41 loc) · 1.36 KB
/
Copy pathset_stl.cpp
File metadata and controls
49 lines (41 loc) · 1.36 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
#include <iostream>
#include <set>
using namespace std;
int main()
{
set<int> mySet; // default increasing order
set<int, greater<int>> mySet2; // decreasing order
for (int i = 1 ; i <= 10 ; i++)
{
// 1-10 masing-masing hanya disimpan 1x
for (int j = 1 ; j <= 10 ; j++) {
mySet.insert(i);
}
}
cout << "ukuran set sekarang : " << mySet.size() << endl;
cout << "elemen - elemen di dalam set : ";
for (set<int>::iterator it = mySet.begin() ; it != mySet.end() ; ++it)
{
cout << *it << " "; //coba tebak kenapa harus pakai asterisk?
}
cout << endl;
for (int i = 7 ; i <= 12 ; i++)
{
if (mySet.count(i))
cout << i << " ada di dalam set" << endl;
else
cout << i << " tidak ada di dalam set" << endl;
}
if(mySet.find(100) == mySet.end()) { // find akan return pointer setelah elemen terakhir jika elemen tidak ditemukan
cout << "100 tidak ada di dalam set" << endl;
} else {
cout << "100 ada di dalam set" << endl;
}
set<int>::iterator lo,hi;
mySet.erase(5); //1 2 3 4 6 7 8 9 10
lo = mySet.lower_bound(4); // ^
hi = mySet.upper_bound(4); // ^
cout << "lower bound ada di index " << *lo << endl;
cout << "upper bound ada di index " << *hi << endl;
return 0;
}