2023-01-06 03:39:19 +08:00
|
|
|
/**
|
2022-11-25 02:04:38 +08:00
|
|
|
* File: stack.cpp
|
2022-11-28 09:04:43 +08:00
|
|
|
* Created Time: 2022-11-28
|
|
|
|
* Author: qualifier1024 (2539244001@qq.com)
|
2022-11-25 02:04:38 +08:00
|
|
|
*/
|
|
|
|
|
2022-11-27 04:19:16 +08:00
|
|
|
#include "../include/include.hpp"
|
|
|
|
|
2022-11-29 02:21:49 +08:00
|
|
|
|
|
|
|
/* Driver Code */
|
|
|
|
int main() {
|
2022-11-28 09:04:43 +08:00
|
|
|
/* 初始化栈 */
|
|
|
|
stack<int> stack;
|
|
|
|
|
|
|
|
/* 元素入栈 */
|
|
|
|
stack.push(1);
|
|
|
|
stack.push(3);
|
|
|
|
stack.push(2);
|
|
|
|
stack.push(5);
|
|
|
|
stack.push(4);
|
|
|
|
cout << "栈 stack = ";
|
|
|
|
PrintUtil::printStack(stack);
|
|
|
|
|
|
|
|
/* 访问栈顶元素 */
|
|
|
|
int top = stack.top();
|
|
|
|
cout << "栈顶元素 top = " << top << endl;
|
|
|
|
|
|
|
|
/* 元素出栈 */
|
|
|
|
stack.pop();
|
2022-11-29 02:21:49 +08:00
|
|
|
cout << "出栈元素 pop = " << top << ",出栈后 stack = ";
|
2022-11-28 09:04:43 +08:00
|
|
|
PrintUtil::printStack(stack);
|
|
|
|
|
|
|
|
/* 获取栈的长度 */
|
|
|
|
int size = stack.size();
|
2022-11-29 02:21:49 +08:00
|
|
|
cout << "栈的长度 size = " << size << endl;
|
2022-11-28 09:04:43 +08:00
|
|
|
|
|
|
|
/* 判断是否为空 */
|
|
|
|
bool empty = stack.empty();
|
2022-11-30 02:27:26 +08:00
|
|
|
cout << "栈是否为空 = " << empty << endl;
|
2022-11-29 02:21:49 +08:00
|
|
|
|
2022-11-28 09:04:43 +08:00
|
|
|
return 0;
|
|
|
|
}
|