哪位高手帮我看看,这个程序运行怎出错!在bitree_node *top_stack(stack *h){return h->top->tree_p
#include<stdio.h>#include<stdlib.h>
#include<malloc.h>
/*树结构类型 */
typedef struct node
{
int elem;
struct node *lchild,*rchild;
}bitree_node;
/*栈结构类型*/
typedef struct stacknode
{
bitree_node * tree_point;
struct stacknode * next;
}stacknode;
typedef struct
{
stacknode * top;
}stack;
stack * h;
/*栈的数据结构*/
void creat_stack(stack *h)
{
h->top=NULL;
}
void push_stack(stack *h,bitree_node *e)
{
stacknode * p;
p=(stacknode *)malloc(sizeof(stacknode));
p->tree_point=e;
p->next=h->top;
h->top=p;
}
void pop_stack(stack *h)
{
stacknode *p;
p=h->top;
h->top=p->next;
free(p);
}
bitree_node *top_stack(stack *h)
{
return h->top->tree_point;
}
int stack_empty(stack *h)
{
if(!h) return 0;
else return 1;
}
/*树的数据结构*/
void creat_tree(bitree_node * bit)
{
int rear=0,root,data;
printf("请输入根结点\n");
scanf("%d",&root);
bit->elem=root;
push(h,bit);
bitree_node *p;
while(1)
{
printf("请输入左孩子\n");
scanf("%d",&data);
if(data!=999)
{
bit=(bitree_node *)malloc(sizeof(bitree_node));
bit->elem=data;
push_stack(h,bit);
bit=bit->lchild;
}
else
{
a: p=top_stack(h);
if(p->lchild!=NULL&&p->rchild!=NULL)
{
pop_stack(h);
goto a;
}
p=p->rchild;
printf("请输入右孩子\n");
scanf("%d",&data);
if(data==999)
{
pop_stack(h);
goto a;
}
p->elem=data;
push_stack(h,p);
if(stack_empty(h)) break;
}
}
}
void main()
{
h=(stack *)malloc(sizeof(stack));
creat_stack(h);
bitree_node * bit;
bit=(bitree_node *)malloc(sizeof(bitree_node));
creat_tree(bit);
}