10978 - 二元搜尋樹recovery   

Description

給一顆二元搜尋樹的preorder
請輸出樹的postorder

 

Input

輸入第一行為一個數字T,代表測資的筆數。
接下來會有T筆測資,每一筆測資第一行有一個數字N
接下來有一行有N個數字為preorder(數字<=2000,且不重複)

測資範圍:
T < 100
0 < N <= 2000

 

 

Output

一行n個數字的數列為postorder,數字間以空白隔開

 

Sample Input  Download

Sample Output  Download

Tags

韩永楷老师数据结构mooc MOOC



Discuss