标签:
#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");
}
标签:
原文地址:http://www.cnblogs.com/panda88/p/4758955.html