Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求大神解释,为什么我先建树,再判断判断叶子加和就是wa,一边建树一边找叶子加和判断就过了呢?void preorder(tree *T,int sum) { if(flag==1) return ; if(T!=0) { sum+=T->data; if(sum==N&&T->left==0&&T->right==0)//当前和等于N并且左右结点都为空就说明该路径符合 { flag=1; return; } preorder(T->left,sum); preorder(T->right,sum); } } 这是我先建树再遍历的代码 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator