void CreateBinTree(BinTree *bt) { char ch; scanf("%c", &ch); getchar(); //读取输入缓冲区中的换行符

if (ch == '#') {
	*bt = NULL;
} else {
	*bt = (BinTree) malloc(sizeof(BinNode));
	(*bt)->data = ch;
	CreateBinTree(&((*bt)->LChild)); //递归创建左子树
	CreateBinTree(&((*bt)->RChild)); //递归创建右子树
}

}

void PreOrder(BinTree bt) { if (bt != NULL) { Visit(bt); PreOrder(bt->LChild); PreOrder(bt->RChild); } }

void InOrder(BinTree bt) { if (bt != NULL) { InOrder(bt->LChild); Visit(bt); InOrder(bt->RChild); } }

void PrintTree(BinTree bt,int nLayer) { if (bt != NULL) { PrintTree(bt->RChild, nLayer+1); //遍历右子树 levelspace(nLayer); //打印非同层节点的空格 Printdata(bt); //打印节点的数据 PrintTree(bt->LChild, nLayer+1); //遍历左子树 }

#include stdioh#include stdlibh结构体定义typedef struct Node 	char data;	struct Node LChild;	struct Node RChild;BinNodeBinTree;函数声明int menu_select;void CreateBinTreeBinTree bt;void PreOrderBinTree bt;void

原文地址: https://www.cveoy.top/t/topic/eQ4W 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录