2024-02-21 09:31:34 +08:00
|
|
|
|
/**
|
|
|
|
|
* File: stack.cpp
|
|
|
|
|
* Created Time: 2022-11-28
|
|
|
|
|
* Author: qualifier1024 (2539244001@qq.com)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "../utils/common.hpp"
|
|
|
|
|
|
|
|
|
|
/* Driver Code */
|
|
|
|
|
int main() {
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* <20><>ʼ<EFBFBD><CABC>ջ */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
stack<int> stack;
|
|
|
|
|
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* Ԫ<><D4AA><EFBFBD><EFBFBD>ջ */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
stack.push(1);
|
|
|
|
|
stack.push(3);
|
|
|
|
|
stack.push(2);
|
|
|
|
|
stack.push(5);
|
|
|
|
|
stack.push(4);
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "ջ stack = ";
|
2024-02-21 09:31:34 +08:00
|
|
|
|
printStack(stack);
|
|
|
|
|
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB>Ԫ<EFBFBD><D4AA> */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
int top = stack.top();
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "ջ<EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD> top = " << top << endl;
|
2024-02-21 09:31:34 +08:00
|
|
|
|
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* Ԫ<>س<EFBFBD>ջ */
|
|
|
|
|
stack.pop(); // <20><EFBFBD><DEB7><EFBFBD>ֵ
|
|
|
|
|
cout << "<EFBFBD><EFBFBD>ջԪ<EFBFBD><EFBFBD> pop = " << top << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD> stack = ";
|
2024-02-21 09:31:34 +08:00
|
|
|
|
printStack(stack);
|
|
|
|
|
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* <20><>ȡջ<C8A1>ij<EFBFBD><C4B3><EFBFBD> */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
int size = stack.size();
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "ջ<EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD> size = " << size << endl;
|
2024-02-21 09:31:34 +08:00
|
|
|
|
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA> */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
bool empty = stack.empty();
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "ջ<EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD> = " << empty << endl;
|
2024-02-21 09:31:34 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|