主题:嫱请问这个程序出了什么问题(遍历二叉树)
#include<iostream.h>
#include<iomanip.h>
#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>
#include<stdafx.h>
#define OVERFLOW -1
#define ERROR 0
#define OK 1
typedef struct BiTNode{//注意采用的是二叉链表作为二叉树的存储结构
TElemType data;
struct BiTNode*lchild,*rchild;
}BiTNode,*BiTree;
Status CreateBiTree_PreOrder(BiTree&T){//先序次序构造二叉树
TElemType ch;
scanf("%c",&ch);
if(ch=='')T=NULL;
else{
if(!(T=(BiTNode*)malloc(sizeof(BiTNode))) exit(OVERFLOW);
T->data=ch;
CreateBiTree_PreOrder(T->lchild);
CreateBiTree-PrOrder(T->rchild);
}
return OK;
}
Status PreOrderTraverse(BiTree T,Status(*Visit)(TElemType e)){//先序遍历
if((*Visit)(T->data))
if(PreOrderTraverse(T->lchild,Visit))
if(PreOrderTraverse(T->rchild,Visit))
return OK;
return ERROR;
}
return OK;
}
Status InOrderTraverse(BiTree T,Status(*Visit)(TElemType e)){//中序遍历
if(T!=NULL){
if(InOrderTraverse(T-lchild,Visit))
if((*Visit)(T->data))
if(InOrderTraverse(T->rchild,Visit))
return OK;
return ERROR;
}
else return OK;
}
Status PostOrderTraverse(BiTree T,Status(*Visit)(TElemType e)){//后序遍历
if(T!=NULL){
if(PostOrderTraverse(T->lchild,Visit))
if(PostOrderTraverse(T->rchild,Visit))
if((*Visit)(T->data))
return ERROR;
}
else return OK;
}
Status Disp(TElemType e){//输出各结点的数据值
printf("%3c",e);
return OK;
}
void main()
{BiTree T;
CreateBiTree_PreOrder(&T);
printf("/n");
PreOrderTraverse(T,Disp);
printf("/n");
InOrderTraverse(T,Disp);
printf("/n");
PostOrderTraverse(T,Disp);
printf("/n");
}
#include<iomanip.h>
#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>
#include<stdafx.h>
#define OVERFLOW -1
#define ERROR 0
#define OK 1
typedef struct BiTNode{//注意采用的是二叉链表作为二叉树的存储结构
TElemType data;
struct BiTNode*lchild,*rchild;
}BiTNode,*BiTree;
Status CreateBiTree_PreOrder(BiTree&T){//先序次序构造二叉树
TElemType ch;
scanf("%c",&ch);
if(ch=='')T=NULL;
else{
if(!(T=(BiTNode*)malloc(sizeof(BiTNode))) exit(OVERFLOW);
T->data=ch;
CreateBiTree_PreOrder(T->lchild);
CreateBiTree-PrOrder(T->rchild);
}
return OK;
}
Status PreOrderTraverse(BiTree T,Status(*Visit)(TElemType e)){//先序遍历
if((*Visit)(T->data))
if(PreOrderTraverse(T->lchild,Visit))
if(PreOrderTraverse(T->rchild,Visit))
return OK;
return ERROR;
}
return OK;
}
Status InOrderTraverse(BiTree T,Status(*Visit)(TElemType e)){//中序遍历
if(T!=NULL){
if(InOrderTraverse(T-lchild,Visit))
if((*Visit)(T->data))
if(InOrderTraverse(T->rchild,Visit))
return OK;
return ERROR;
}
else return OK;
}
Status PostOrderTraverse(BiTree T,Status(*Visit)(TElemType e)){//后序遍历
if(T!=NULL){
if(PostOrderTraverse(T->lchild,Visit))
if(PostOrderTraverse(T->rchild,Visit))
if((*Visit)(T->data))
return ERROR;
}
else return OK;
}
Status Disp(TElemType e){//输出各结点的数据值
printf("%3c",e);
return OK;
}
void main()
{BiTree T;
CreateBiTree_PreOrder(&T);
printf("/n");
PreOrderTraverse(T,Disp);
printf("/n");
InOrderTraverse(T,Disp);
printf("/n");
PostOrderTraverse(T,Disp);
printf("/n");
}