键盘输入栈-CPP,哪里出错了,达不到结果

问题遇到的现象和发生背景

在这里描述函数接口。例如:
void InOutS(SeqStack& S, int x);
在这里给出函数被调用进行测试的例子。例如:
#include
using namespace std;

#define MAXSIZE 5 // 假定预分配的栈空间最多为5个元素
typedef int SElemType; // 假定栈元素的数据类型为字符

typedef struct SqStack
{
SElemType data[MAXSIZE];
int top;
}*SeqStack;

void InitStack(SeqStack& S)
{
S = new SqStack;
S->top = -1;
}

bool EmptyStack(SeqStack S)
{
return S->top == -1;
}

void Push(SeqStack& S, SElemType e)
{
if (S->top == MAXSIZE - 1)
return;

S->data[++S->top] = e;

}

void Pop(SeqStack& S, SElemType& e)
{
if (EmptyStack(S))
return;

e = S->data[S->top--];

}

/* 请在这里填写答案 */

int main()
{
SeqStack S;
int n, x;
InitStack(S);

cin >> n;

for (int i = 0; i < n; i++) {
    cin >> x;
    InOutS(S, x);
}

return 0;

}
输入样例
8
1 2 3 -1 -1 -1 -1 4

用代码块功能插入代码,请勿粘贴截图

在这里描述函数接口。例如:

void InOutS(SeqStack& S, int x){

   int top=0,i;int n=8;
    for(i=0;i>x;
       if(x!=-1){
            if(top==MAXSIZE-1){cout<<"栈满"<exit(1); }
              else S->data[++S->top]=x;}
        if(x==-1){
            if(top==0){cout<<"栈空"<exit(0);}
   
      else cout<<"出栈元素是"<data[S->top--]<
运行结果及报错内容

栈空

我的解答思路和尝试过的方法

哪个环节出错了?

我想要达到的结果

出栈元素是 3
出栈元素是 2
出栈元素是 1
栈空