add null check to findNodeSuchThat

This commit is contained in:
parrt 2017-04-06 15:41:21 -07:00
parent 9519bfc36f
commit 5616e370e4
1 changed files with 2 additions and 0 deletions

View File

@ -249,6 +249,8 @@ public class Trees {
public static Tree findNodeSuchThat(Tree t, Predicate<Tree> pred) {
if ( pred.test(t) ) return t;
if ( t==null ) return null;
int n = t.getChildCount();
for (int i = 0 ; i < n ; i++){
Tree u = findNodeSuchThat(t.getChild(i), pred);