#define MaxSize 100 ;
#define TEM 10 ;
typedef struct{
int *top ;
int *base ;
int stacksize;
}SqStack1;//定义int整型数字栈
void InitStack(SqStack1 *p) //构造一个空栈p
{
p->base=(int*)malloc(100*sizeof(int));
if(!p->base) exit(0);
p->top = p->base ;
p->stacksize = 100 ;
}
void Push(SqStack1 *p , int e )//插入元素e为新的栈顶元素
{
if(p->top - p->base >= p->stacksize) {
p->base = (int*)realloc(p->base,(p->stacksize + 10)*sizeof(int));
if(!p->base) exit(0);
p->top = p->base + p->stacksize;
p->stacksize += TEM ;
}
*p->top++ = e ;
}
int Pop (SqStack1 *p , int *e )//出栈
{
if(p->top == p->base ) exit(0);
p->top--;
*e = *p->top ;
return(*e);
}
输入就是插入元素e为新的栈顶元素,输出则是元素出栈,出栈后返回e,其中,e的类型根据需要定!