简体   繁体   中英

In Binary search tree program Codeblock is printing weird characters

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM