静态实现(数组)
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
struct Node{
char value;
int lson, rson;
}tree[N];
int index=1;
int newNode(char val)
{
tree[index].value=val;
tree[index].lson=tree[index].rson=0;
return index++;
}
void insert(int &father,int child,int l_r){
if(l_r==0)
tree[father].lson=child;
else
tree[father].rson=child;
}
int dfn[N]={0};
int dfn_timer=0;
void dfn_order(int father)
{
if(father!=0){
dfn[father]=++dfn_timer;
printf("dfn[%c]=%d;",tree[father].value,dfn[father]);
dfn_order(tree[father].lson);
dfn_order(tree[father].rson);
}
}
int visit_timer=0;
void visit_order(int father)
{
if(father!=0){
printf("visit[%c]=%d;",tree[father].value,++visit_timer);
visit_order(tree[