6_33_两个一维数组判断u是否为v的子孙
#include<stdio.h> int L[6+1]={0,2,4,0,6,0,0}; int R[6+1]={0,3,5,0,0,0,6}; int n=6; int IfSon(int u,int v) { if(u&&v){ if(L[v]==u||R[v]==u) return 1; else return(IfSon(u,L[v])||IfSon(u,R[v])); } return 0; } int main() { printf("%d\n",IfSon(5,1)); }
版权声明:本文为博主原创文章,未经博主允许不得转载。