We had a test question about what this function was outputting for the binary tree and even the smartest student in the class only got a 3/10. The test is over and he will not be telling us the answer as this is how he always is. I was going to ask on here what is the output of this? I ran it and it seemed like it was printing both sides of the binary tree and then the entire thing.
This is the tree we were given. I cant draw the lines, but just imagine them.
It won't print anything since it won't compile. But assuming the errors (unmatched opening braces) are not in the original then it's actually pretty easy.
h
d l
b f j n
a c e g i k m o
ptr is calling ptrAgain postorder.
The postorder of the nodes is:
a c b e g f d i k j m o n l h
ptrAgain prints the subtree rooted at each of those nodes inorder, so:
-a
-c
-a b c
-e
-g
-e f g
-a b c d e f g
-i
-k
-i j k
-m
-o
-m n o
-i j k l m n o
-a b c d e f g h i j k l m n o
EDIT: This seems to confirm that the above is correct.