I know what the output would be when we traverse a binary tree with a post order algorithm from left to right, however I am having a bit of trouble seeing what it would be when we go from right to left. For example, would the output of a post order traversal of the following tree be "9 9 8 7 3 2 1 2 6 7"? Or would it be "9 9 7 8 3 2 1 2 6 7"? Or am I wrong in both cases? 7 3 9 2 6 8 9 1 2 7
Asked
Active
Viewed 317 times
0
-
1As introduction to your question, the proposed list `7 3 9 2 6 8 9 1 2 7` has duplicate values. Please confirm that because in a BST _"duplicates are not allowed to be inserted"_ (see that post ["BST - Inserting an equal value element"](http://stackoverflow.com/a/9384858/6945651)) – J. Piquard Mar 19 '17 at 20:12
1 Answers
0
Assuming your tree is simplebinary tree
instead of binary search tree
your output should be -
9 8 9 7 6 2 1 2 3 7
Actually you can simply use this function to get post order from right to left-
void post(struct Node*root){
if(root==NULL)
return;
if(root->right)
post(root->right);
if(root->left)
post(root->left);
printf("%d ",root->data);
}
whereprintf
is function to print data if you dont know C.

monster
- 808
- 10
- 23