#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define stack_init_size 100
#define stackincrement 10
typedef int ElemType;
typedef struct {
ElemType *base;
ElemType *top;
int stacksize;
}sqstack;
void initstack(sqstack *s)
{
s->base=(ElemType *)malloc(stack_init_size*sizeof(ElemType));
if(!s->base)
exit(0);
s->top=s->base;
s->stacksize=stack_init_size;
}
void push(sqstack *s,ElemType e)
{
printf("插入元素:");
scanf("插入的元素为:%d",&e);
if(s->top-s->base>=s->stacksize)
{
s->base=(ElemType *)realloc(s->base,(s->stacksize+stackincrement)*sizeof(ElemType));
if(!s->base)
exit (0);
s->top=s->base+s->stacksize;
s->stacksize+=stackincrement;
}
*(s->top)=e;
s->top++;
}
int main()
{
sqstack *s;
ElemType e;
initstack(s);
push(s,e);
return 0;
}