当前位置:网站首页>4274. Suffix expression - binary expression tree
4274. Suffix expression - binary expression tree
2022-07-02 19:28:00 【linengcs】
- Postorder traversal of binary expression tree is suffix expression
- special case : How to distinguish positive signs from plus signs in expressions , What about minus signs and minus signs ?
answer : If a node is “+” or “-” Number , And its left subtree is empty , Then the symbol is positive ( negative ) Number , Not plus or minus , Then the node is traversed first rather than second
ACCode
#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int t[N][2], vis[N];
int n;
string v[N];
void traverse(int node)
{
if (node == -1)
return;
if ((v[node] == "-" || v[node] == "+") && t[node][0] == -1)
{
cout << "(" << v[node];
traverse(t[node][1]);
cout << ")";
}
else
{
cout << "(";
traverse(t[node][0]);
traverse(t[node][1]);
cout << v[node];
cout << ")";
}
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> v[i] >> t[i][0] >> t[i][1];
if (t[i][0] != -1)
vis[t[i][0]] = 1;
if (t[i][1] != -1)
vis[t[i][1]] = 1;
}
int p;
for (int i = 1; i <= n; i++)
{
if (!vis[i])
{
p = i;
break;
}
}
traverse(p);
return 0;
}
边栏推荐
- According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors
- [test development] takes you to know what software testing is
- 《重构:改善既有代码的设计》读书笔记(下)
- Emmet basic syntax
- 性能测试如何创造业务价值
- xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
- Which video recording software is better for the computer
- Data dimensionality reduction factor analysis
- ORA-01455: converting column overflows integer datatype
- 【ERP软件】ERP体系二次开发有哪些危险?
猜你喜欢

Transformation of thinking consciousness is the key to the success or failure of digital transformation of construction enterprises

高级性能测试系列《24. 通过jdbc执行sql脚本》

【测试开发】软件测试—概念篇
![[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter](/img/c4/3bba96fda92328704c2ddd929dcdf6.png)
[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter

Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径

The difference between interceptor and filter

Yunna | why use the fixed asset management system and how to enable it

Excel查找一列中的相同值,删除该行或替换为空值

云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
![[0701] [论文阅读] Alleviating Data Imbalance Issue with Perturbed Input During Inference](/img/c7/9b7dc4b4bda4ecfe07aec1367fe059.png)
[0701] [论文阅读] Alleviating Data Imbalance Issue with Perturbed Input During Inference
随机推荐
Usage of ieda refactor
4274. 后缀表达式-二叉表达式树
What is the MySQL backup suffix_ MySQL backup restore
第七章-类基础
Emmet基础语法
Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
A4988驱动步进电机「建议收藏」
【测试开发】一文带你了解什么是软件测试
高级性能测试系列《24. 通过jdbc执行sql脚本》
Reading notes of code neatness
Npoi export Excel2007
mybatiesHelperPro工具必须的可以生成到对应项目文件夹下
juypter notebook 修改默认打开文件夹以及默认浏览器
【ERP软件】ERP体系二次开发有哪些危险?
Digital scroll strip animation
Data dimensionality reduction principal component analysis
Which video recording software is better for the computer
使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
Compile oglpg-9th-edition source code with clion
Page title component