How would you print out the data in a binary tree, level by
level, starting at the top?
Answer Posted / vadim
print tree by levels not recursive in C language
typedef struct treeNode{
int data;
struct treeNode* left;
struct treeNode* right;
} TreeNode;
typedef struct tree{
TreeNode* root;
} Tree;
typedef struct listNode{
TreeNode* dataPtr;
struct listNode* next;
struct listNode* prev;
} ListNode;
typedef struct list
{
ListNode* head;
ListNode* tail;
} List;
//main function : you still will need to write all the mini
functions that i have used here ...
void printByLevels(Tree tr)
{
TreeNode *curr;
List *lst;
lst=(List *)malloc(sizeof(List));
makeEmptyList(lst);
insertDataToStartDList(lst,tr.root);
while(isEmptyList(lst)!=TRUE)
{
curr=lst->tail->dataPtr;
if (curr->left!=NULL)
insertDataToStartDList(lst,curr->left);
if(curr->right!=NULL)
insertDataToStartDList(lst,curr->right);
printf("%d ",curr->data);
RemoveLastNodeInList(lst);
}//while
}
| Is This Answer Correct ? | 3 Yes | 1 No |
Post New Answer View All Answers
In c programming language, how many parameters can be passed to a function ?
What is assert and when would I use it?
What is wrong with this initialization?
Is a house a mass structure?
What is the difference between exit() and _exit() function?
Is there any demerits of using pointer?
#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }
the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above
what are the 10 different models of writing an addition program in C language?
Write a program to check prime number in c programming?
`write a program to display the recomended action depends on a color of trafic light using nested if statments
What does s c mean in text?
The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is??? please help me on this
What is the return type of sizeof?
Explain void pointer?