标签:
如此简单了明 DFS前中后
1 #include<stdio.h> 2 int a[100],b[100]; 3 void A(int i) 4 { 5 printf("%d ",i); 6 if(a[i]) 7 A(a[i]); 8 if(b[i]) 9 A(b[i]); 10 } 11 void B(int i) 12 { 13 if(a[i]) 14 B(a[i]); 15 printf("%d ",i); 16 if(b[i]) 17 B(b[i]); 18 } 19 void C(int i) 20 { 21 if(a[i]) 22 C(a[i]); 23 if(b[i]) 24 C(b[i]); 25 printf("%d ",i); 26 } 27 int main() 28 { 29 int n,i; 30 scanf("%d",&n); 31 for(i=1;i<=n;i++) 32 scanf("%d%d",&a[i],&b[i]); 33 A(1);//qian 34 printf("\n"); 35 B(1);//zhong 36 printf("\n"); 37 C(1);//hou 38 return 0; 39 }
标签:
原文地址:http://www.cnblogs.com/babyyang/p/5304629.html