那位前辈讲讲这是为什么??实在想不明白
#include <stdlib.h>#include <stdio.h>
typedef char ElemType;
typedef int Status;
#define ERROR 0
#define OK 1
#define STACK_INIT_SIZE
typedef struct linknode
{
ElemType data;
struct linknode *next;
}LiStack;
void InitStack(LiStack *S)
{
//S=(LiStack *)malloc(sizeof(LiStack));
S->next=NULL;
printf("Init successfully!\n");
}
void ClearStack(LiStack *S)
{
LiStack *p;
while(S->next!=NULL)
{
p=S;
S=S->next;
free(p);
}
free(S);
printf("OVER");
}
void StackLength(LiStack *S)
{
int i=0;
LiStack *q;
q=S;
while(q->next!=NULL)
{
q=q->next;
i++;
}
printf("The length is:%d\n",i);
}
void StackEmpty(LiStack *S)
{
if(S->next!=NULL)
printf("The stack is not empty!\n");
else
printf("The stack is empty!\n");
}
void Push(LiStack *S,ElemType e)
{
LiStack *p;
p=(LiStack *)malloc(sizeof(LiStack));
p->data=e;
p->next=S->next;
S->next=p;
printf("push %c successful!\n",e);
}
void Pop(LiStack *S,ElemType e)
{
LiStack *p;
if(S->next!=NULL)
{
p=S->next;
e=p->data;
printf("%c\n",e);
S=S->next;
}
}
void GetTop(LiStack *S,ElemType e)
{
if(S->next!=NULL)
e=S->next->data;
printf("The top elem is:%c\n",e);
}
void DispStack(LiStack *S)
{
LiStack *p;
p=S;
while(p->next!=NULL)
{
printf("\t%c\n",p->next->data);
p=p->next;
}
}
void main()
{
LiStack *S;
ElemType a='a',b='b',c='c',d='d',e='e';
S=(LiStack*)malloc(sizeof(LiStack));
InitStack(S);
StackEmpty(S);
Push(S,a);
Push(S,b);
Push(S,c);
Push(S,d);
Push(S,e);
StackEmpty(S);
StackLength(S);
DispStack(S);
StackEmpty(S);
ClearStack(S);
}
我就搞不懂了,为什么红色部分 //S=(LiStack *)malloc(sizeof(LiStack));不注释就会出错???
麻烦那位前辈讲讲????