如何才能解决数据的插入?
#include<stdio.h>#include<stdlib.h>
#define StackSize 100
typedef int DataType;
typedef struct {
DataType data[StackSize];
int top;
}SeqStack;
void InitStack(SeqStack *S)
{
S->top=-1;
}
void Push(SeqStack *S,DataType x )
{
if(S->top==StackSize-1){printf("上溢"); exit(-1);}
S->data[++S->top]=x;
}
DataType Pop(SeqStack *S){
int x;
if(S->top==-1 ) {printf("下溢");exit(-1);}
x=S->data[S->top--];
return x;
}
DataType GetTop(SeqStack *S)
{
if(S->top==-1){printf("下溢");exit(-1);}
return S->data[S->top];
}
int Empty(SeqStack *S)
{
if(S->top==-1) return 1;
else return 0;
}
main (){
int t;
int x,y;
SeqStack S;
printf("请输入您要进行的操作:");
printf("1:入栈 2:出栈 3:取栈顶元素 4:栈遍历 \n ");
scanf("%d ",&t);
switch(t)
{
case 1: printf("请输入入栈的数\n");
scanf("%d",&x);
Push(&S,x);
case 2: x=Pop(&S);printf("%d",x);
case 3: y=GetTop(&S); printf("%d",y);
case 4: Empty(&S);
}
}