I am trying to print this tree:
1
/ \
2 3
/ / \
4 5 6
In this way:
1
2 3
4 5 6
I wrote this code:
void print_g(Tree t)
{
Queue q=initQueue();
Tree tmp=initTree();
if(!isTreeEmpty(t))
enqueue(q,t);
while(!isQueueEmpty(q))
{
tmp=dequeue(q);
printf("%d ",*((int *)Root(tmp)));
if(!isTreeEmpty(subLeft(tmp)))
enqueue(q,subLeft(tmp));
if(!isTreeEmpty(subRight(tmp)))
enqueue(q,subRight(tmp));
}
}
But this code is printed like this:
123456
I can't think of an idea how to solve the print issue. Can someone write the Pseudo Code??
Thanks.