# include"iostream.h"
#include"stdlib.h"
#define STACKSIZE 100
typedef int ElemType;
typedef struct {ElemType   data    [ STACKSIZE ] ;
                             int   top;   } sqstack;


/*补充InitStack初始化栈算法*/
void Initstack(sqstack &S)
{
    S.top=0;

}
/*补充push入栈算法*/
void  Push(sqstack &S,ElemType e)
{
    if(S.top==STACKSIZE)
    {
        cout<<"栈满.";
        exit(0);
    
    }
    else{S.top=S.top+1;
    S.data[S.top-1]=e;}
}

/*补充pop出栈算法*/
int pop(sqstack &S,ElemType &e)
{
    if(S.top==0)
return -1;
else  {S.top--;
e=S.data[S.top];
return 0;
}
}

//主函数部分:
void main()
{sqstack y; 
 int n,i;
 ElemType e;
Initstack(y); 
cout<<"栈已建好   !";
cout<<"\n";
cout<<"请输入N的值,它代表 栈中元素个数:";
 cin>> n;
cout<<"进栈操作为:\n";

 //入栈操作
for(i=1;i<=n;i++)
{cin>>e;
Push(y,e);
cout<<"\n";
}

cout<<"\n";

cout<<"出栈元素序列为:\n";

 //出栈操作
for(i=1;i<=n;i++)
{ 
    pop(y,e);
    cout<<e<<"\n";
    cout<<"\n";
}
}