1.按照先序创建二叉树
void Create(BiTree& pRoot) { char ch; cin >> ch; if (ch == '#') { pRoot = NULL; } else { pRoot = (BiTNode*)malloc(sizeof(BiTNode)); pRoot->data = ch; Create(pRoot->lchild); Create(pRoot->rchild); } }
2.先序遍历二叉树
void PreRoot(BiTNode* T) { if (T != NULL) { cout << T ->data <<endl; if (T->lchild) { PreRoot(T->lchild); } if (T->rchild) { PreRoot(T->rchild); } } }