题意:给出一个语法树(二叉树),输出相应的中缀表达式。

思路:很显然,通过中序遍历来做。通过观察,发现除了根结点之外的所有非叶结点的两侧都要输出括号,故在中序遍历时判断一下即可。

代码:

#include <cstdio>
#include <cstring>
struct Node{
    ];
    int left,right;
}Tree[];
;//根结点

void inOrderTraversal(int v)
{
    ){
         || Tree[v].right!=-)) printf("(");
        inOrderTraversal(Tree[v].left);
        printf("%s",Tree[v].data);
        inOrderTraversal(Tree[v].right);
         || Tree[v].right!=-)) printf(")");
    }
}

int main()
{
    ];
    memset(isRoot,true,sizeof(isRoot));
    int n;
    scanf("%d",&n);
    ;i<=n;i++){
        scanf("%s %d %d",Tree[i].data,&Tree[i].left,&Tree[i].right);
        ) isRoot[Tree[i].left]=false;
        ) isRoot[Tree[i].right]=false;
    }
    while(isRoot[root]==false) root++;
    inOrderTraversal(root);
    ;
}

1130 Infix Expression的更多相关文章

  1. PAT甲级 1130. Infix Expression (25)

    1130. Infix Expression (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Give ...

  2. PAT 1130 Infix Expression[难][dfs]

    1130 Infix Expression (25 分) Given a syntax tree (binary), you are supposed to output the correspond ...

  3. PAT甲级——1130 Infix Expression (25 分)

    1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...

  4. PAT 甲级 1130 Infix Expression

    https://pintia.cn/problem-sets/994805342720868352/problems/994805347921805312 Given a syntax tree (b ...

  5. PAT 1130 Infix Expression

    Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with pa ...

  6. 1130. Infix Expression (25)

    Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with pa ...

  7. PAT甲题题解-1130. Infix Expression (25)-中序遍历

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789828.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  8. PAT1130:Infix Expression

    1130. Infix Expression (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Give ...

  9. A1130. Infix Expression

    Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with pa ...

随机推荐

  1. LeetCode第[22]题(Java):Generate Parentheses

    题目:制造括号序列 难度:Medium 题目内容: Given n pairs of parentheses, write a function to generate all combination ...

  2. 《JavaScript高级程序设计》第6章补充 继承

    基于原型链继承 将父类的实例赋给子类的prototype来实现继承. 原理:父类的实例有父类所有的实例属性和原型方法,将它赋给子类的prototype后,子类的创建的实例就有会__proto__属性指 ...

  3. Linux软件安装-----apache安装

    一. ./configure --prefix=/usr/local/http2 \ --enable-modules=all \ --enble-mods-shared=all \ 开启模块共享: ...

  4. 新东方雅思词汇---8.3、apt

    新东方雅思词汇---8.3.apt 一.总结 一句话总结:本身为词根 adj. 恰当的:有…倾向的:灵敏的 本身为词根 英 [æpt]  美 [æpt]  adj. 恰当的:有…倾向的:灵敏的 n. ...

  5. yii2:模块

    yii2:模块 模块不同于frontend/frontback单独的前后台单独的主题项目,模块不能单独部署,必须属于某个应用主体(如前后台:frontend/frontback). 模块置于modul ...

  6. CMD下利用subst命令将一个文件夹镜像成本地的一个虚拟磁盘

    我们都知道net use可以建立网络驱动器映射,这里不说了. 我今天刚看到这命令的,叫镜像虚拟磁盘subst命令,这个命令可以简化好多操作,比如一个常用的文件放在一个路径很深的文件夹中,每次我们想要操 ...

  7. MVVM3

    MVVM设计模式 2010-09-19 23:59:18|  分类: MVVM |  标签:mvvm  silverlight4  mvc  mvp  command  |举报|字号 订阅     一 ...

  8. 四十 Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)倒排索引

    倒排索引 倒排索引源于实际应用中需要根据属性的值来查找记录.这种索引表中的每一项都包括一个属性值和具有该属性值的各记录的地址.由于不是由记录来确定属性值,而是由属性值来确定记录的位置,因而称为倒排索引 ...

  9. ASP.NET Core 简单引入教程

    0.简介 开源.跨平台 1.环境安装 参考官方教程   Core 官方文档 2.向世界问个好 sheel/cmd 下: dotnet --help // 查看帮助 dotnet new *     / ...

  10. git一个系列教程

    https://git-scm.com/book/zh/v1/%E8%B5%B7%E6%AD%A5-%E5%85%B3%E4%BA%8E%E7%89%88%E6%9C%AC%E6%8E%A7%E5%8 ...