帮我看看这个有没有问题,运行正常
#include <stdio.h>#include <malloc.h>
typedef struct Stack
{
int data;
struct Stack * snext;
}Stack;
typedef structpStack
{
struct Stack * top;
struct Stack * base;
int stacksize;
}pStack;
typedef struct pStack * PS;
intInitStack(PS);
int Push(PS,int );
int Pop(PS,int *);
int ShowStack(PS);
int GetStackNum(PS);
int main()
{
pStack S;
int e=100;
InitStack(&S);
Push(&S,100);
Push(&S,200);
Push(&S,300);
Push(&S,1700);
Push(&S,1500);
ShowStack( &S);
Pop(&S,&e);
printf("1.[%d] 出栈\n",e);
Pop(&S,&e);
printf("2.[%d] 出栈\n",e);
Pop(&S,&e);
printf("3.[%d] 出栈\n",e);
Pop(&S,&e);
printf("4.[%d] 出栈\n",e);
ShowStack( &S);
int i=0;
i=GetStackNum(&S);
printf("栈中的数据个数:%d \n",i);
getchar();
return 1;
}
int GetStackNum(PS S)
{
return S->stacksize;
}
int Pop(PS S,int *e)
{
Stack *s;
s=S->top;
*e=s->data;
S->top=s->snext;
free(s);
S->stacksize--;
return 1;
}
int Push(PS S,int e)
{
Stack *p;
p=(Stack *)malloc(sizeof(Stack));
if(!p)
return 0;
p->snext=S->top;
p->data=e;
S->top=p;
S->stacksize++;
return 1;
}
int ShowStack(PS S)
{
Stack *p=S->top;
while (p!=S->base)
{
printf("%d \n",p->data);
p=p->snext;
}
return 1;
}
int InitStack(PS S)
{
S->base=(Stack *)malloc(sizeof(Stack));
if(!S->base)
return 0;
S->top=S->base;
S->base->snext=NULL;
S->stacksize=0;
return 1;
} 你要实现什么,你怀疑可能出问题的地方在哪里
页:
[1]