关于二叉树非递归遍历是指针调用的问题
#define STACK_INIT_SIZE 100#define STACKINCREMENT 10
#include <stdio.h>
#include <stdlib.h>
typedef char TElemType;
typedef struct BiTNode
{
TElemType data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
typedef struct
{
BiTree *base;
BiTree *top;
int stacksize;
}SqStack;
void initialStack(SqStack *s)
{
s->base=(BiTree *)malloc(STACK_INIT_SIZE*sizeof(BiTree));
if(!s->base) exit(0);
s->top=s->base;
s->stacksize=STACK_INIT_SIZE;
}
void Push(SqStack *s,BiTNode *e)
{
if(s->top-s->base>=s->stacksize)
{
s->base=(BiTree *)realloc(s->base,(STACK_INIT_SIZE+STACKINCREMENT)*sizeof(BiTree));
if(!s->base) exit(0);
s->top=s->base+s->stacksize;
s->stacksize+=STACKINCREMENT;
}
*(s->top)++=e;
}
void Pop(SqStack *s,BiTree *e)
{
if(s->top==s->base) exit(0);
*e=*--(s->top);
}
int GetTop(SqStack *s,BiTree *e)
{
if(s->top==s->base) return(0);
*e=*(s->top-1);
return(1);
}
int StackEmpty(SqStack *s)
{
if(s->base==s->top)
return(1);
else
return(0);
}
void CreatBiTree(BiTree *T)
{
TElemType ch;
scanf("%c",&ch); fflush(stdin);
if(ch=='#')
*T=NULL;
else
{
*T=(BiTNode *)malloc(sizeof(BiTNode));
if(!*T)
exit(0);
(*T)->data=ch;
CreatBiTree(&(*T)->lchild);
CreatBiTree(&(*T)->rchild);
}
}
void Visit(char p)
{
printf("%c",p);
}
void InOrderTraverse(BiTree T)
{
SqStack S;
BiTree p;
initialStack(&S);
p=T;
while(p||!StackEmpty(&S))
{
if(p)
{
Push(&S,p);
p=p->lchild;
}
else
{
Pop(&S,&p);
Visit(p->data);
p=p->rchild;
}
}
}
void main()
{
BiTree *t;
printf("jianlishu:\n");
printf("shurijieidian:");
CreatBiTree(t);
printf("zhongshubianlidejieguowei:");
InOrderTraverse(*t);
printf("\n");
}
不理解在构建二叉树中和遍历的时候,请解释一下 详细一点