Given an array pre[] of N nodes representing preorder traversal of BST. The task is to print its postorder traversal.
Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case is N, the size of the array. The second line of each test case contains N input as pre[i].
Output:
Postorder traversal of the given preorder traversal is printed.
Examples:
Input:
T = 1
N = 8
pre[120 90 96 105 240 270 300 360]
Output:
105 96 90 360 300 270 240 120
Input:
T = 1
N = 5
pre[80 60 70 160 200]
Output:
70 60 200 160 80
Pseudo Code:
C++ Implementation:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer