BTNode* CreateTree(char* s, int &i, int len)
// 利用先序遍历创建二叉树
// 参数:先序遍历字符串s,字符串初始下标i=0,字符串长度len。
// 返回:二叉树
{
// 请在这里补充代码,完成本关任务
/********** Begin *********/
BTNode* root;
if(s[i]=='#'||i>len){
i++; //判断没有孩子节点后,手动后移
return NULL;
}
root = getNewNode(s[i++]); //创建根节点
root->lchild = CreateTree(s, i, len); //递归创建左子树
root->rchild= CreateTree(s, i, len); //递归创建右子树
return root;
/********** End **********/
}
// 二叉树的中序遍历
// 参数:二叉树根节点root
// 输出:中间没有空格,末尾不换行。
void InOrder(BTNode* root)
{
// 请在这里补充代码,完成本关任务
/********** Begin *********/
if(root!=NULL){
InOrder(root->lchild);
cout<<root->data;
InOrder(root->rchild);
}
/********** End **********/
}