void createTree(TreeNode** T,char * data,int* index)
{
char ch;
ch = data[*index];
*index += 1;
if (ch == '#')
{
//it is empty node
*T = nullptr;
}
else
{
*T = (TreeNode*)malloc(sizeof(TreeNode));
(*T)->data = ch;
(*T)->flag = false;
createTree(&((*T)->lchild),data,index); // the logc of creating the left tree is the same
createTree(&((*T)->rchild),data,index); //create the right tree
}
}
二、遍历
1.前序遍历
void preOrder(TreeNode* T)
{
/*
This funciton is to traverse the element from
the roots to thechild.
*/
if (T == nullptr)
{
return;
}
else
{
//
cout << T->data;
preOrder(T->lchild);
preOrder(T->rchild);
}
}