mirror of
https://github.com/xlucn/PAT.git
synced 2026-11-05 06:37:35 +08:00
15 lines
1.9 KiB
HTML
15 lines
1.9 KiB
HTML
Tree Traversals
|
|
<div class="ques-view"><p>Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.</p>
|
|
<h3 id="input-specification-">Input Specification:</h3>
|
|
<p>Each input file contains one test case. For each case, the first line gives a positive integer <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span> (<span class="katex"><span class="katex-mathml"><math><mrow><mo>≤</mo><mn>3</mn><mn>0</mn></mrow>\le 30</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.78041em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mrel">≤</span><span class="mord mathrm">3</span><span class="mord mathrm">0</span></span></span></span>), the total number of nodes in the binary tree. The second line gives the postorder sequence and the third line gives the inorder sequence. All the numbers in a line are separated by a space.</p>
|
|
<h3 id="output-specification-">Output Specification:</h3>
|
|
<p>For each test case, print in one line the level order traversal sequence of the corresponding binary tree. All the numbers in a line must be separated by exactly one space, and there must be no extra space at the end of the line.</p>
|
|
<h3 id="sample-input-">Sample Input:</h3>
|
|
<pre><code class="lang-in">7
|
|
2 3 1 5 7 6 4
|
|
1 2 3 4 5 6 7
|
|
</code></pre>
|
|
<h3 id="sample-output-">Sample Output:</h3>
|
|
<pre><code class="lang-out">4 1 6 3 5 7 2
|
|
</code></pre>
|
|
</div> |