请教一个数据结构中栈的问题,用C编的
#include "stdio.h"#include "stdlib.h"
#include "math.h"
typedef struct STACK{
int *base;
int *top;
int stacksize;
}sqstack;
typedef struct LNode{
int data;
struct LNode *next;
}LNode,*linklist;
sqstack Build(sqstack *s){
s->base=malloc(100*sizeof(int));
s->top=s->base;
s->stacksize=100;
return *s;
}
int GetTop(sqstack *s ,int e){
if(s->top==s->base)
exit (0);
e=*(s->top-1);
return e;
};
void push(sqstack *q,int e){
if (q->top-q->base==q->stacksize)
{
q->base=malloc((q->stacksize+10)*sizeof(int));
if(!q->base)exit;
q->top=q->base+q->stacksize;
q->stacksize+=10;
}
*q->top++=e;
}
void pop(sqstack *q,int e){
if (q->base==q->top)
{
exit;
}
e=*--q->top;
}
main()
{
int a[256];
int n;
int i=0;
int j=0;
int e;
sqstack *S;
Build(S);
S->top=-1;
printf("input n:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("input a[%d]",i);
scanf("%d",a[i]);
push(S,a[i]);
}
while (S->base!=S->top)
{
pop(S,e);
printf("%d",e);
}
}
这段代码,编译连接没有问题,但是一运行就出错,类似的程序写了好几个了,都是类似情况,头疼,求教~