stack 的入门
2015-08-25 22:56
246 查看
#include "iostream"
#include "stack"
using namespace std;
void main12()
{
stack <int> s; //定义一个栈
for (int i = 0; i < 5; i++)
{
//往栈里面赋值
s.push(i);
}
while (!s.empty())
{
int tmp = s.top(); //获取栈顶的元素
s.pop(); //弹出栈顶的元素
cout << tmp << endl;
}
system("pause");
}
struct Teacher
{
int age;
char name[10];
};
void printf_stack(stack<Teacher> &s)
{
while (!s.empty())
{
cout << s.top().age << endl;
s.pop();
}
}
void main()
{
//定义一个栈
Teacher t1, t2, t3;
t1.age = 11;
t2.age = 22;
t3.age = 33;
stack<Teacher> s;
s.push(t1);
s.push(t2);
s.push(t3);
printf_stack(s);
system("pause");
}
#include "stack"
using namespace std;
void main12()
{
stack <int> s; //定义一个栈
for (int i = 0; i < 5; i++)
{
//往栈里面赋值
s.push(i);
}
while (!s.empty())
{
int tmp = s.top(); //获取栈顶的元素
s.pop(); //弹出栈顶的元素
cout << tmp << endl;
}
system("pause");
}
struct Teacher
{
int age;
char name[10];
};
void printf_stack(stack<Teacher> &s)
{
while (!s.empty())
{
cout << s.top().age << endl;
s.pop();
}
}
void main()
{
//定义一个栈
Teacher t1, t2, t3;
t1.age = 11;
t2.age = 22;
t3.age = 33;
stack<Teacher> s;
s.push(t1);
s.push(t2);
s.push(t3);
printf_stack(s);
system("pause");
}
相关文章推荐
- python_学习笔记0825
- iphone开发之UIButton按钮的使用(二)拖线实现 多个按钮用同一个监听方法实现
- group by cube 用法
- git 学习
- hdoj 1698 Just a Hook【线段树区间修改】
- php微信开发 (获取用户地理位置)
- 安装Apache时可能会遇到的问题
- 1.大数据基础(上)_2.大数据的商业应用
- CCCamera,CCAtlasNode源码解析
- gdb调试多线程
- 扩展KMP - HDU 4333 Revolving Digits
- Android应用开发之所有动画使用详解
- 树状数组模拟3个元素的排序 Codeforces 12D Ball
- ORM对象关系映射
- find命令学习小结
- ReactJS入门二
- 解决win10 关键错误开始菜单和cortana无法工作 的问题
- 阿里云部署Web API 总结(及其他可能部署方式)
- JavaScript 学习笔记 (一)
- jsoncpp库使用注意事项