?? 前序表轉(zhuǎn)化.txt
字號(hào):
//將用邊表示的樹轉(zhuǎn)化為前序表示的樹
//傳入節(jié)點(diǎn)數(shù)n和鄰接表list[],鄰接表必須是雙向的,會(huì)在函數(shù)中釋放
//pre[]返回前序表,map[]返回前序表中的節(jié)點(diǎn)到原來節(jié)點(diǎn)的映射
#define MAXN 10000
struct node{
int to;
node* next;
};
void prenode(int n,node* list[],int* pre,int* map,int* v,int now,int last,int& id){
node* t;
int p=id++;
for (v[map[p]=now]=1,pre[p]=last;list[now];){
t=list[now],list[now]=t->next;
if (!v[t->to])
prenode(n,list,pre,map,v,t->to,p,id);
}
}
void makepre(int n,node* list[],int* pre,int* map){
int v[MAXN],id=0,i;
for (i=0;i<n;v[i++]=0);
prenode(n,list,pre,map,v,0,-1,id);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -