/*
Args:
* s:the string of preorder traversal sequence.
for example:
if you want to obtain an element of s,you can write the code:
DataType data = *((*s));
if you want to obtain the second element of s,you can write the code:
(*s)++;
DataType data = *((*s));
Return:
* Pointer of the bitree node.
Description:
* Create a bitree from preorder traversal sequence.
*/
BinaryTree CreateBinaryTreeFromPreOrderSequence(DataType **s)
{
DataType ch;
BinaryTree *T;
ch = (*(*s));
if (ch == '*')
*T = NULL;
else
{
*T = (BinaryTree)malloc(sizeof(BinaryNode));
if (!*T)
exit(0);
(*T)->data = ch;
(*s)++;
(*T)->left=CreateBinaryTreeFromPreOrderSequence(*(*s));
(*T)->right= CreateBinaryTreeFromPreOrderSequence(*(*s));
}
return *T;
}
DataType ch;
BinaryTree *T;
这些你都顺手给个初始值