您的位置:首页 > 其它

nyoj 202 中序遍历二叉树

2016-04-28 15:29 176 查看
#include<iostream>
using namespace std;
struct node{
int L,R;
}Tree[11];
void InorderTraverse(int root){
if(Tree[root].L!=-1) InorderTraverse(Tree[root].L);
cout<<root<<endl;
if(Tree[root].R!=-1) InorderTraverse(Tree[root].R);
}
int main(){
int i,T,root,lchild,rchild,N,M;
cin>>T;
while(T--){
cin>>N;
for(i=0;i<N;i++){
cin>>root>>lchild>>rchild;
Tree[root].L=lchild;
Tree[root].R=rchild;
}
for(cin>>M;M--;cin>>root>>rchild);
InorderTraverse(0);
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: