-
Notifications
You must be signed in to change notification settings - Fork 0
/
std.cpp
128 lines (90 loc) · 3.39 KB
/
std.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>
#include <vector>
#include <stack>
#include <map>
int main(void) {
std::cout << "============================================================\n"
<< " vector test \n"
<< "============================================================\n";
std::vector<int> vec;
std::cout << vec.empty();
for (int i = 0; i < 5; i++)
vec.push_back(i * 10);
for (std::vector<int>::iterator it = vec.begin(); it != vec.end(); it++)
std::cout << *it << " ";
std::cout << "\n";
for (std::vector<int>::reverse_iterator rit = vec.rbegin(); rit != vec.rend(); rit++)
std::cout << *rit << " ";
std::cout << "\n";
std::cout << vec.size() << "\n";
vec.resize(10, 42);
std::cout << "\n";
for (size_t i = 0; i < vec.size(); i++)
std::cout << vec[i] << " ";
std::cout << "\n";
vec.pop_back();
for (size_t i = 0; i < vec.size(); i++)
std::cout << vec.at(i) << " ";
std::cout << "\n";
vec.reserve(20);
std::cout << vec.capacity() << "\n";
std::cout << vec.front() << "\n";
std::cout << vec.back() << "\n";
vec.insert(vec.begin() + 1, 3, 999);
for (size_t i = 0; i < vec.size(); i++)
std::cout << vec[i] << " ";
std::cout << "\n";
vec.erase(vec.end() - 5);
for (size_t i = 0; i < vec.size(); i++)
std::cout << vec[i] << " ";
std::cout << "\n";
vec.assign(5, 10);
for (size_t i = 0; i < vec.size(); i++)
std::cout << vec[i] << " ";
std::cout << "\n";
std::vector<int> copy_vec = vec;
for (size_t i = 0; i < copy_vec.size(); i++)
std::cout << copy_vec[i] << " ";
std::cout << "\n";
std::cout << (vec == copy_vec) << " " << (vec != copy_vec) << "\n";
std::cout << "============================================================\n"
<< " stack test \n"
<< "============================================================\n";
std::stack<int> st;
for (int i = 1; i < 6; i++)
st.push(i * 11);
std::cout << st.empty() << "\n";
std::cout << st.size() << "\n";
std::stack<int> copy_st = st;
std::cout << (st == copy_st) << " " << (st != copy_st) << "\n";
while (!st.empty()) {
std::cout << st.top() << " ";
st.pop();
}
std::cout << "\n";
std::cout << st.empty() << "\n";
std::cout << "============================================================\n"
<< " map test \n"
<< "============================================================\n";
std::map<char, int> mp;
mp['a'] = 10;
mp['b'] = 20;
mp['c'] = 30;
mp.insert(std::make_pair('d', 40));
mp.insert(std::make_pair('e', 50));
std::cout << mp.empty() << "\n";
std::cout << mp.size() << "\n";
for (std::map<char, int>::iterator it = mp.begin(); it != mp.end(); it++)
std::cout << it->first << ", " << it->second << "\n";
std::cout << "a : " << mp.at('a') << "\n";
std::cout << "b : " << mp['b'] << "\n";
mp.erase(mp.find('b'));
for (std::map<char, int>::reverse_iterator rit = mp.rbegin(); rit != mp.rend(); rit++)
std::cout << rit->first << ", " << rit->second << "\n";
std::cout << mp.count('a') << "\n";
std::cout << mp.lower_bound('b')->first << "\n";
std::cout << mp.upper_bound('d')->first << "\n";
std::map<char, int> copy_mp = mp;
std::cout << (mp == copy_mp) << " " << (mp != copy_mp) << "\n";
return (0);
}