Home > Back-end >  For help, where is this function has a problem
For help, where is this function has a problem

Time:04-18

TreeNodePtr createTreeWithLevelOrder (int * data, int size) {
QueuePtr Q;
Q=InitQueue ();
TreeNodePtr T;
ListNodePtr find;
int i;
TreeNodePtr Node;
TreeId=1;
for(i=0; I{
The Node=createTreeNode (data [I], NULL, NULL);
The EnQueue (Q, the Node);
}
T=GetHead (Q);
If (T - & gt; Val==1)
{
Free (Q);
return NULL;
}
while(! QueueEmpty (Q))
{
The Node=GetHead (Q);
DeQueue (Q);
If (Node - & gt; Val!=1) {
The find=Q - & gt; DummyHead - & gt; next;
While (find)
{
If (the find - & gt; Node - & gt; Id==(2 * (Node - & gt; Id)))
{
If (the find - & gt; Node - & gt; Val==1)
{
Node - & gt; Left=NULL;
}
The else
{
Node - & gt; Left=find - & gt; The node;
}
If (the find - & gt; Next)
{
The find=find - & gt; next;
If (the find - & gt; Node - & gt; Val==1)
{
Node - & gt; Right=NULL;
}
The else
{
Node - & gt; Right=find - & gt; The node;
}
}
break;
}
The else find=find - & gt; next;
}
}
}
Free (Q);
return T;
}
This function is achieved by the queue level traversal build a binary tree, want to ask what went wrong, thank you
  • Related