Hi Edward
Sorry, been hung up. I have looked at your referenced code on pastebin. First off, here is some advice to make your code a little more reusable - it is not necessary for it to work, but please consider it.
(1) Put your call counters in an array. In this way, lines 84-764 in your program can be replaced by
1 2
|
countCall[tempTree.current->info]++;
tempTree.deleteTree(root);//delete the first element of the queue
| |
(2) Use named constants instead of magic numbers in your code.
I don't mean to flame you, this is hard-earned experience! If you come back to this program in 6 months you will have no idea what the program is doing and it is very hard to extend.
Now, for the question:
My problem as I was thinking last night was how to delete the nodes after I read them should I traverse the left side first all the way to the bottom of left tree side starting with the leaf nodes (if(tempTree.current->llink == NULL)) then delete that specific node and then start to work upwards towards the root node. then do the right side and finally the node...
|
Yes. Exactly. Work your way down the left branch with recursive calls. Delete on the way back. Repeat for the right subtree. Then, finally, delete the node itself.
The rationale is: Leaf nodes are safe to delete. When you find a leaf node you will know that it is safe to delete. When you have deleted both the left and right subtrees of a node you will know that the node is now a leaf and hence safe to delete.
Take a look at
the code snippet in my 2nd posting above. It does exactly that :)
/Corpus