求助刚入门的,二叉树的建立及前后层序遍历,出错啊
#include "stdlib.h"
#include "stdafx.h"
#include<stdio.h>
struct node
{
int data;
struct node * l,*r;
};
struct node *CreateTree()
{
int x;
scanf("%d",&x);
if(x==0) return NULL;
struct node*t;
t=new struct node;
t->data=x;
printf("输入%d的左",x);
t->l=CreateTree();
printf("输入%d的右",x);
t->r=CreateTree();
return t;
}
void printTree(struct node * t) /*前序遍历*/
{
if(t==NULL) return;
printf("%d",t->data );
printTree(t->l);
printTree(t->r);
}
void PostTree(struct node * t)/*后序遍历*/
{
if(t==NULL) return;
printTree(t->l);
printTree(t->r);
printf("%d",t->data );
}
void LevelTree(struct node * t)/*层次遍历*/
{
InitQueue(Q);
if(t==NULL) return;
while(!QueueEmpty(Q) )
{
DeQueue(Q,t);
visite(t->data);
if(t->l) EnQueue(Q,t->l);
if(t->r) EnQueue(Q,t->r);
}
}
int main(int argc, char* argv[])
{
struct node*root;
printf("输入树的根节点\n");
root=CreateTree();
printTree(root);
printf("是前序遍历\n");
PostTree(root);
printf("是后序遍历\n");
return 0;
}