来源:互联网 发布:一颗五角星的淘宝买家 编辑:程序博客网 时间:2024/06/06 07:27
#include <iostream>using namespace std;struct stack{int *data;int top;int max;stack(){max=10;top=-1;data=new int[max];}~stack(){delete []data;}};void Push(stack &s,int i){if(s.top<s.max-1){s.top++;s.data[s.top]=i;}}void Pop(stack &s){if(s.top!=-1){cout<<s.data[s.top]<<' ';s.top--;}}void main(){stack s;for(int i=0;i<20;i++)Push(s,i);for(int i=0;i<10;i++)Pop(s);system("pause");}

0 0