|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 这是她 于 2020-6-18 20:45 编辑
Difficulties strengthen the mind,as labor does the body.
Stack
Stack是一种先进后出的数据结构。
栈中只有顶端的元素才可以被外界使用,因此栈不允许有遍历行为。
- #include<iostream>
- #include<stack>
- using namespace std;
- void test1()
- {
- //入栈——push
- //出栈——pop
- //返回栈顶——top
- //判断栈是否为空——empty
- //返回栈大小——size
-
- //符合先进后出
- stack<int> s1;
-
- //入栈
- s1.push(100);
- s1.push(200);
- s1.push(300);
-
- while (!s1.empty())
- {
- cout << "栈顶元素是: " << s1.top() << endl;
- s1.pop();
- }
- cout << "栈的大小是: " << s1.size() << endl;
-
- }
- int main()
- {
- test1();
-
- return 0;
- }
复制代码
|
|