被这里的指针搞乱了,大家帮忙看看
#include<stdio.h>#include<stdlib.h>
#define MAXNUM 100
struct BiTreeNode; /*二叉树中的结点*/
typedef struct BiTreeNode *PBiTreeNode;/*结点的指针类型*/
struct BiTreeNode
{
char info;
PBiTreeNode llink;
PBiTreeNode rlink;
};
//typedef struct BiTree *PBiTree;
typedef struct BiTreeNode *BiTree;
struct SeqStack
{
BiTree s[MAXNUM];
int t;
};
typedef struct SeqStack *PSeqStack;
PSeqStack createEmptyStack_seq(void)
{
PSeqStack pastack;
pastack = (PSeqStack)malloc(sizeof(struct SeqStack));
if(pastack == NULL)
printf("Out of space!!\n");
else
pastack->t = -1;
return (pastack);
}
int isEmptyStack_seq(PSeqStack pastack)
{
return(pastack->t == -1);
}
void push_seq(PSeqStack pastack, PBiTreeNode p)
{
if(pastack->t >= MAXNUM -1)
{
printf("Overflow!\n");
}
else
{
pastack->t = pastack->t + 1;
pastack->s[pastack->t] = p->s[pastack->t];
}
}
void pop_seq(PSeqStack pastack)
{
if(pastack->t == -1)
printf("Underflow! \n");
else
pastack->t = pastack->t - 1;
}
int top_seq(PSeqStack pastack)
{
return(pastack->s[pastack->t]);
}
PBiTree createTree(PBiTree bt)
{
char ch;
//printf("please input data:\n");
scanf("%c",&ch);
if(ch=='#')
{
bt=NULL;
}
else
{
bt=(BiTree)malloc(sizeof (BiTreeNode));
if(!t)
exit(0);
bt->data=ch;
bt->lchild=CreateTree(bt->lchild);
bt->rchild=CreateTree(bt->rchild);
}
return t;
}
void PreOder(PBiTree bt)
{
PSeqStack pastack;
BiTreeNode *c;
if(t==NULL)
return;
pastack=createEmptyStack_seq();
push_seq( pastack, bt);
while(!isEmptyStack_seq(pastack))
{
c=top_seq(pastack);
pop_seq(pastack);
if(c!=NULL)
{
printf("%c".c->data);
push_seq( pastack, llink);
push_seq( pastack, rlink);
}
}
}
int main()
{
PBiTree bt=NULL;
bt=createTree(bt);
printf("Pre Order:\n");
PreOder(bt);
return 0;
}