二叉树的结构体:左右子树指针(Tree *) 值(int)
typedef struct Tree { char data; struct Tree* lchild, * rchild; } * BiTree;
二叉树的先序创建
BiTree Create() { char ch;scanf_s("%c", &ch); BiTree T = NULL; if (ch == '#')T = NULL; else { T = (BiTree)malloc(sizeof(Tree)); T->data = ch; T->lchild = Create(); T->rchild = Create(); } return T; }
二叉树的中序输出
void TLROut(BiTree T) { if (T) { TLROut(T->lchild); cout << T->data; TLROut(T->rchild); } }
交换左右子树
void ChangeTree(BiTree T) { BiTree temp = NULL; if (T){ temp = T->rchild; T->rchild = T->lchild; T->lchild = temp; ChangeTree(T->lchild); ChangeTree(T->rchild); } else return; }
标签:lchild,ch,BiTree,Tree,---,二叉树,rchild,数据结构 From: https://www.cnblogs.com/yetang307/p/16821799.html