Update stack.cpp
翻译大佬的Java代码
This commit is contained in:
parent
c1d2e0de09
commit
3b1607c9a4
@ -6,3 +6,33 @@
|
|||||||
|
|
||||||
#include "../include/include.hpp"
|
#include "../include/include.hpp"
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
/* 初始化栈 */
|
||||||
|
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();
|
||||||
|
cout<<"出栈元素 pop = "<< top <<",出栈后 stack = ";
|
||||||
|
PrintUtil::printStack(stack);
|
||||||
|
|
||||||
|
/* 获取栈的长度 */
|
||||||
|
int size = stack.size();
|
||||||
|
cout<<"栈的长度 size = "<<size<<endl;;
|
||||||
|
|
||||||
|
/* 判断是否为空 */
|
||||||
|
bool empty = stack.empty();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user