一个求二叉树路径的程序显示不了输出结果
我编了一个求二叉树的根结点到所有叶子结点路径的程序,但是显示不了输出结果,请高手帮忙看下错在哪了?#include<stdlib.h>
#include<stdio.h>
#include<malloc.h>
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define OK 1
#define NULL 0
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef char Status ;
typedef char ElemType;
struct STACK
{
ElemType *base;
ElemType *top;
int stacksize;
};
typedef struct STACK SqStack;
typedef char DataType;
typedef struct Node{
DataType data;
struct Node *lchild,*rchild;
}BintNode;
typedef BintNode *bintree;//定义二叉链表指针类型
//初始化栈
Status InitStack(SqStack *S)
{
S->base=(ElemType *)malloc(STACK_INIT_SIZE*sizeof(ElemType));
if(!S->base) return ERROR;
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return OK;
}
//进栈
Status Push(SqStack *S,ElemType e)
{
if(S->top - S->top>=S->stacksize)
{
S->base=(ElemType *) realloc(S->base,
(S->stacksize + STACKINCREMENT) * sizeof(ElemType));
if(!S->base) return ERROR;
S->top=S->base+S->stacksize;
S->stacksize+=STACKINCREMENT;
}
*(S->top++)=e;
return OK;
}
//出栈
Status Pop(SqStack *S,ElemType e)
{
if(S->top==S->base) return ERROR;
e=*--(S->top);
return OK;
}
createbintree(bintree *t)
{
char ch;
if ((ch=getchar())=='#')
*t=NULL;
else{
*t=(BintNode*)malloc(sizeof(BintNode));
(*t)->data=ch;
createbintree(&(*t)->lchild);
createbintree(&(*t)->rchild);
}
return OK;
}
AllPath(bintree T,SqStack *s)//求解函数
{
if(T!=NULL)
{
Push(s,T->data);
if(T->lchild!=NULL&&T->rchild!=NULL)printf("%c,",T->data);
else{
AllPath(T->lchild,s);
AllPath(T->rchild,s);
}
Pop(s,T->data);
}
}
main()//主函数
{
bintree T;
SqStack *s;
printf("please input nodes of bintree:\n");
createbintree(&T);
AllPath(T,s);
}