typedef struct node Binary_Tree;
typedef struct node
{
int data;
struct node *leftnode;
struct node *rightnode;
}Binary_Tree,*Tree;
u8 Make_BinaryTree( Binary_Tree *tree , int *p )
{
static int *q; q=p;
if( *q==0)
{
tree=NULL;
q++;
return 0;
}
else
{
tree=(Binary_Tree *)malloc(sizeof(Binary_Tree));
tree->data=*q;
printf("%d \n", tree->data);
q++;
Make_BinaryTree( tree->leftnode , q );
Make_BinaryTree( tree->rightnode ,q );
}
return 0;
}
void Initialization_BinaryTree(void)
{
int array[]={1,2,3,0,0,4,0,0,5,6,0,0,7,0,0 };
Binary_Tree tree;
Make_BinaryTree( &tree , &array[0] );
printf("%d \n" ,tree.data);
printf("%d \n" ,tree .rightnode->data);
printf("%d \n" ,tree.leftnode->data);
这三个输出都是乱码,我不知道二叉树的建立过程中问题在哪里,我应该在每个节点都分配了内存,不过结果好像有问题
}
|