#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<stack> #include<string> #include<iostream> #include<queue> using namespace std; const int N=1005; int a[N],l[N],r[N],f[N],root; void print1(int rt){ if(rt!=0){ cout<<a[rt]<<" "; print1(l[rt]); print1(r[rt]); } } void print2(int rt){ } void print2(int rt){ } int main(){ cin>>n; for(int i=1,h,v,x,y;i<=n;i++){ cin>>h>>v>>x>>y; a[h]=v; l[h]=x; r[h]=y; f[x]=h; f[y]=h; } for(int i=1;i<=n;i++){ if(f[i]==0){ root=i; break; } } print1(root); print2(root); print3(root); }
理解问题#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<stack> #include<string> #include<iostream> #include<queue> using namespace std; const int N=1005; int a[N],l[N],r[N],f[N],root; void print1(int rt){ if(rt!=0){ cout<<a[rt]<<" "; print1(l[rt]); print1(r[rt]); } } void print2(int rt){ } void print2(int rt){ } int main(){ cin>>n; for(int i=1,h,v,x,y;i<=n;i++){ cin>>h>>v>>x>>y; a[h]=v; l[h]=x; r[h]=y; f[x]=h; f[y]=h; } for(int i=1;i<=n;i++){ if(f[i]==0){ root=i; break; } } print1(root); print2(root); print3(root); }
已完成理解「#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<stack> #include<string> #include<iostream> #include<queue> using namespace std; const int N=1005; int a[N],l[N],r[N],f[N],root; void print1(int rt){ if(rt!=0){ cout<<a[rt]<<" "; print1(l[rt]); print1(r[rt]); } } void print2(int rt){ } void print2(int rt){ } int main(){ cin>>n; for(int i=1,h,v,x,y;i<=n;i++){ cin>>h>>v>>x>>y; a[h]=v; l[h]=x; r[h]=y; f[x]=h; f[y]=h; } for(int i=1;i<=n;i++){ if(f[i]==0){ root=i; break; } } print1(root); print2(root); print3(root); }」
展开阅读网页