include <stdio.h>
define MAXSIZE 10
typedef int SElemType;
typedef struct {
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
void InitSqStack(SqStack *sq){
int i;
sq->base=(SqStack ) malloc(MAXSIZEsizeof(SqStack));
if(!sq->base){
printf("init fail \n");
exit(0);
}
sq->top=sq->base;
printf("top%p\n",sq->top);
printf("base%p\n",sq->base);
sq->stacksize=MAXSIZE;
printf("init success \n");
}
void push(SqStack *sq,SElemType e ){
int i;
if(sq->top-sq->base>= MAXSIZE){
}
printf("e%p\n",&e);
//sq->top[0]=e;
*(sq->top)=e;
printf("top%p\n",sq->top);
sq->top++;
i=sq->top-sq->base;
printf("top%p\n",sq->top);
printf("base%p\n",sq->base);
printf("top-base=%d\n",i);
}
void pop(SqStack *sq,SElemType * e ){
int i=4;
sq->top--;
printf("%d ",sq->top[0]);
printf("top%p\n",sq->top);
*e=sq->top[0];
printf("e%p\n",e);
}
void vist(SqStack sq){
int i=sq.top-sq.base;
int j=i-1;
printf("%d\n",i);
printf("(");
while(i>0){
printf("%d ",sq.base[j]);
i--;
j--;
}
printf(")\n");
}
int main(){
SqStack sq;
int p;
InitSqStack(&sq);
vist(sq);
push(&sq,1);
push(&sq,2);
push(&sq,3);
push(&sq,4);
printf("p%p\n",p);
pop(&sq,&p);
printf("p%p\n",p);
vist(sq);
printf("p=%d\n",p);
return 0;
}