前序建立二叉树 (字符0表示该处为空)
#include "stdafx.h"
#include "string.h"
#include "stdio.h"
struct node
{
char value;
node *left;
node *right;
node()
{
left=right=NULL;
}
};
void CreatTree(char * ch,int &point,int length,node * &root)
{
if(point<length)
{
char temp=ch[point++];
if(temp=='0')
root=NULL;
else
{
root=new node;
root->value=temp;
CreatTree(ch,point,length,root->left);
CreatTree(ch,point,length,root->right);
}
}
}
void MidScan(node * tree)
{
if(tree!=NULL)
{
printf("%c",tree->value);
MidScan(tree->left);
MidScan(tree->right);
}
}
int main(int argc, char* argv[])
{
char * ch="abc000d00";
node *tree=NULL;
int point=0;
CreatTree(ch,point,strlen(ch),tree);
MidScan(tree);
return 0;
}