I was making program which can take postfix expression and then will create a binary expression tree of that expression .My program was running perfectly .I was testing my program by copy /pasting some samples postfix expression but the problem is now it is not printing inorder, post order and preorder but infact it is printing one weird character. While testing I might have accidentally pressed function key. I am not sure what is causing this problem. Please help me out in identifying my mistake .
This the output. please tell me why it is printing this character after a and not the expression.
You don't initialize leftChild
and rightChild
members of BTnode
s you allocate. These pointers contain random garbage; they are generally not NULL
.
When you traverse the tree, you eventually descend down to a leaf node and then attempt to traverse further down through these garbage pointers. Whereupon the program exhibits undefined behavior.