[已解决问题]
解决于 2017-05-03 07:52
include using namespace std;struct BiTree{ char data; BiTree lchild, rchild;};void CreatBiTree(BiTree &T){ char ch; cin >> ch; if (ch = '#') T = NULL; else { T = new BiTree; T->data = ch; CreatBiTree(T->lchild); CreatBiTree(T->rchild); }}void adorder(BiTree T)//先序遍历{ if (T) { cout << T->data; adorder(T->lchild); adorder(T->rchild); } }void inorder(BiTree T)//中序遍历{ if (T) { inorder(T->lchild); cout << T->data; inorder(T->rchild); }}void laorder(BiTree T)//后序遍历{ if (T) { adorder(T->lchild); adorder(T->rchild); cout << T->data; }}void Copy(BiTree T, BiTree &newT)//复制二叉树{ if (T) { newT = new BiTree; newT->data = T->data; Copy(T->lchild, newT->lchild); Copy(T->rchild, newT->rchild); }}int Depth(BiTree T)//计算二叉树的深度{ int m, n; if (T) { m = Depth(T->lchild); n = Depth(T->rchild); if (m >= n) return m + 1; else return n + 1; }}int Nodecount(BiTree T)//统计二叉树T中的节点个数{ if (T) return Nodecount(T->lchild) + Nodecount(T->lchild) + 1;}void main(){ BiTree *T; T = new BiTree; CreatBiTree(T); cout << "先序遍历:"; adorder(T); cout << "中序遍历;"; inorder(T); cout << "后序遍历:"; laorder(T);}
创新思
|
菜鸟二级
|
园豆:
208
提问于:2017-04-19 09:34