#include<iostream> using namespace std; #define MAXSIZE 1000 typedef int ElemType; typedef struct { ElemType data[MAXSIZE]; int top;/*用于栈顶指针*/ }SqStack; /*进栈操作*/ void Push(SqStack *S, ElemType e){ if (S->top == MAXSIZE - 1){ cout << "此栈已满"; } S->top++; S->data[S->top] = e; } /*出栈操作*/ void Pop(SqStack *S){ ElemType e = 0; if (S->top == -1){ cout << "此栈已空"; } e = S->data[S->top]; cout << e << endl; S->top--; } int main(){ SqStack *S = new SqStack; S->top = -1; Push(S, 1); Push(S, 2); Push(S, 3); Push(S, 4); Pop(S); Pop(S); Pop(S); Pop(S); }