抽象数据类型栈
#include "stdio.h"#include "stdlib.h"
#include "malloc.h"
#define maxsize 100
#define zenl 10
typedef struct
{
int *base;
int *top;
int stacksize;
}sqstack;
void cj(sqstack *s)
{
s->base=(int *)malloc(maxsize*sizeof(int));
if(s->base==NULL)
exit(1);
s->top=s->base;
s->stacksize=maxsize;
}
void quding(sqstack *s,int *e)
{
if(s->top==s->base)
printf("栈满");
e=s->top-1;
}
void push(sqstack *s,int e)
{
if(s->top-s->base>=s->stacksize)
{
s->base=(int *)realloc(s->base,(s->stacksize+zenl)*sizeof(int));
if(s->base==NULL)
exit(1);
s->top=s->base+s->stacksize;
s->stacksize+=zenl;
}
*(s->top)++=e;
}
void pop(sqstack *s,int *e)
{
if(s->top==s->base)
printf("错误");
s->top--;
*e = *(--s->top);
}
void main()
{
int n;
sqstack *p;
cj(p);
do
{printf("请输入要进栈元素: ");
scanf("%d",&n);
push(p,n);
}while(n>=0);
}
编译后没有错误....
运行就弹出错误窗口..
请指点一下..
多谢了~
还有就是抽象数据类型到底是怎么回事?