Given a syntax tree (binary), you are supposed to output the corresponding postfix expression, with parentheses reflecting the precedences of the operators.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (≤ 20) which is the total number of nodes in the syntax tree. Then N lines follow, each gives the information of a node (the i-th line corresponds to the i-th node) in the format:
data left_child right_child
where data is a string of no more than 10 characters, left_child and right_child are the indices of this node's left and right children, respectively. The nodes are indexed from 1 to N. The NULL link is represented by −1. The figures 1 and 2 correspond to the samples 1 and 2, respectively.

该博客详细介绍了如何将给定的二叉语法树转换为后缀表达式,强调了从节点编号构建树以及利用深度优先搜索(DFS)策略进行转换的方法。内容包括输入输出规格说明、样例输入输出以及问题分析和满分代码示例。
最低0.47元/天 解锁文章
944

被折叠的 条评论
为什么被折叠?



