求大神帮忙解决下面代码的问题,关于栈的。
编译通过,可是在运行的时候,出栈根本不显示~求大神帮忙解决~代码如下:#include <stdio.h>
#include <malloc.h>
typedef char ElemType;
typedef struct lsnode{
ElemType data;
struct lsnode *next;
}LinkStack;
void InitStack(LinkStack *ls)
{
ls = NULL;
}
int StackEmpty(LinkStack *ls)
{
if(ls == NULL)
return 1;
else
return 0;
}
void Push(LinkStack *ls,ElemType x)
{
LinkStack *p;
p = (LinkStack *)malloc(sizeof(LinkStack));
p ->data = x;
p ->next = ls;
ls = p;
}
int Geop(LinkStack *ls,ElemType *x)
{
if(ls == NULL)
return 0;
else
{
*x = ls ->data;
return 1;
}
}
int Pop(LinkStack *ls,ElemType *x)
{
LinkStack *p;
if(ls == NULL)
return 0;
else
{
p = ls;
*x = p ->data;
ls = p ->next;
free(p);
return 1;
}
}
void main(void)
{
LinkStack *ls;
ElemType e;
ls = (LinkStack *)malloc(sizeof(LinkStack));
InitStack(ls);
printf("Stack %s\n",(StackEmpty(ls)==1?"empty":"inempty"));
printf("Push a into Stack\n");
Push(ls,'a');
printf("Push b into Stack\n");
Push(ls,'b');
printf("Push c into Stack\n");
Push(ls,'c');
printf("Push d into Stack\n");
Push(ls,'d');
printf("Stack %s\n",(StackEmpty(ls)==1?"empty":"inempty"));
Geop(ls,&e);
printf("Get the top one:%c\n",e);
printf("Pop in order\n");
while(!StackEmpty(ls))
{
Pop(ls,&e);
printf("%c\n",e);
}
printf("\n");
}