class StlTest {
public:
void testStack() {
stack<int> s;
for (int i=0; i<5; i++) {
s.push(i);
cout << s.top() << endl; // 1 2 3 4 5
}
cout << "size : " << s.size() << endl; // 0
while (!s.empty()) {
cout << s.top() << endl; // 5 4 3 2 1
s.pop();
}
}
void testQueue() {
queue<char> q;
char str[20] = "hello";
for (int i=0; i<10; i++) {
q.push(str[i]);
cout << q.back() << endl; // h e l l o
}
while (!q.empty()) {
cout << q.front() << endl; // h e l l o
q.pop();
}
}
void testPriQueue() {
/*
* 定义:priority_queue<Type, Container, Functional>
* Type 就是数据类型,
* Container 就是容器类型&#
05-22
1764
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-26
1153
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-19
2424
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)