1、#include #include typedef struct btnodechar data;struct btnode * Llink;struct btnode * Rlink;btnode,*btree;/创建void CreateTree(btree *root)char ch;ch = getchar();if(ch = .)*root = NULL;else*root = (btree)malloc(sizeof(btnode);(*root) - data = ch;CreateTree(CreateTree(/输出void PrintTree(btree root,int
2、nLayer)if(root = NULL)return;PrintTree(root - Llink,nLayer + 1);PrintTree(root - Rlink,nLayer + 1);for(int i = 0;i data);PreOrder(root - Llink);PreOrder(root - Rlink);/中序遍历显示二叉树void InOrder(btree root)if(root != NULL)InOrder(root - Llink);printf(“ %c “,root - data);InOrder(root - Rlink);/后序遍历显示二叉树vo
3、id PostOrder(btree root)if(root != NULL)PostOrder(root - Llink);PostOrder(root - Rlink);printf(“ %c “,root - data);/显示叶子结点个数int leaf(btree root)int LeafCount;if(root = NULL)LeafCount = 0;else if (root - Llink = NULL)elseLeafCount = leaf(root - Llink)+leaf(root - Rlink);return LeafCount;void Menu()pr
4、intf(“*“);printf(“n(1) 创建二叉树。“);printf(“n(2) 二叉树图形。“);printf(“n(3) 先序遍历显示树。“);printf(“n(4) 中序遍历显示树。“);printf(“n(5) 后序遍历显示树。“);printf(“n(6) 统计该树叶子节点个数。“);printf(“n(0) 退出。“);printf(“n*“);void ActionMenu(btree *lroot)int n = 1;btree flag = NULL,root = *lroot;char e,e1,e2;int depth = 0,h = 1,cflag = 0;w
5、hile(n)printf(“nn 请选择一个操作:“);scanf(“%d“,switch(n)case 1:printf(“请输入二叉树:“);getchar();CreateTree(break;case 2:printf(“该二叉树图形为:n“);PrintTree(root,1);break;case 3:printf(“先序遍历显示:“);PreOrder(root);printf(“n“);break;case 4:printf(“中序遍历显示:“);InOrder(root);printf(“n“);break;case 5:printf(“后序遍历显示:“);PostOrder(root);printf(“n“);break;case 6:printf(“该树的叶子节点数目为:%dn“,leaf(root);break;case 0:break;default:printf(“非法输入!n“);void main()btree rootx = NULL;Menu();ActionMenu(