【树论】二叉树的序遍历

原题传送门

思路


此题是本蒟蒻迈向黄金段位的最后一道题,然而本蒟蒻只用了10min便搞⛏掉了它QAQ,看来自己还是有进步的!!!

TIPS

前序遍历:根-左-右
中序遍历:左-根-右
后序遍历:左-右-根
然后大爆搜就ojbk啦~~~

Code


#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

struct ints
{
    int l;
    int r;
    ints(){l=r=0;}
    ints(int a,int b){l=a;r=b;}
};
map gmap;
int n,i,gleft,gright,maxdepth,maxwidth;
int wide[10];

void dfs1(int no)
{
    if(no==0)
        return;
    cout<>n;
    for(int i=1;i<=n;i++)
    {
        cin>>gleft>>gright;
        gmap[i]=ints(gleft,gright);
    }
    dfs1(1);
    cout<

你可能感兴趣的:(【树论】二叉树的序遍历)