请高手帮忙解决一下下面的程序,编译没有错误,但运行出错,请指出错误也以为我讲解一下链表的创建过程。

#include "stdio.h"
#include "stdlib.h"
//定义结构体
typedef struct zu
{
char data;
struct zu *next;
}linkstack;
linkstack *push(linkstack *top,char a);
void pop(linkstack *top);

void main()
{
char c[5];
int i;
linkstack *top;
printf("请输入只有左右括号组成的字符\n");
scanf("%s",c);
for(i=0;i<5;i++)
if(c[i]=='(')
{
push(top,'(');
}
else
{
pop(top);
}
if(top==NULL)
printf("配对成功\n");
else
printf("配对不成功\n");

}

//进栈函数
linkstack *push(linkstack *top,char a)
{
linkstack *p;
p=(linkstack *)malloc(sizeof(linkstack));
if(p=NULL)
{
printf("申请空间失败\n");
return 0;
}
else
{
p->data=a;
p->next=top->next;
top=p;
return top;
}

}

//出栈函数
void pop(linkstack *top)
{
linkstack *p;
p=top->next;
if(p==NULL)
printf("链栈不存在");
else
{
top->next=p->next;
free(p);
}
}

第1个回答  2011-05-01
top 没有赋值
相似回答