zoukankan      html  css  js  c++  java
  • 扩展二叉树 (根据特殊的前序遍历建树)

    【题目描述】

    <=>   ABD..EF..G..C..

    【题目链接】

        http://ybt.ssoier.cn:8088/problem_show.php?pid=1340

    【代码】

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int a=1;
     4 int lc[110],rc[110];
     5 char puz[110];
     6 char parse(int& i)
     7 {
     8     int cur=i;
     9     if(puz[cur]!='.') {
    10         i++;
    11         lc[cur]=parse(i);
    12        // cout<<puz[cur]<<" lc= "<<puz[lc[cur]]<<endl;
    13         i++;
    14         rc[cur]=parse(i);
    15        // cout<<puz[cur]<<" rc= "<<puz[rc[cur]]<<endl;
    16     }
    17     return cur;
    18 }
    19 void mid(int i)
    20 {
    21     if(puz[i]=='.') return;
    22     mid(lc[i]);
    23     printf("%c",puz[i]);
    24     mid(rc[i]);
    25 }
    26 void post(int i)
    27 {
    28     if(puz[i]=='.') return;
    29     post(lc[i]);
    30     post(rc[i]);
    31     printf("%c",puz[i]);
    32 }
    33 int main()
    34 {
    35     gets(puz+1);
    36     parse(a);
    37     mid(1);
    38     puts("");
    39     post(1);
    40     return 0;
    41 }
  • 相关阅读:
    TensorFlow基础篇
    MySql分类
    VISUAL STUDIO 调试
    排序分类
    位分类
    Visio分类
    工作线程AfxBeginThread的使用
    Windows Live Writer配置步骤
    用户界面线程AfxBeginThread的使用
    WIndows 相关知识
  • 原文地址:https://www.cnblogs.com/Willendless/p/9410645.html
Copyright © 2011-2022 走看看