Advertisement
Extend the class BinaryTree to include a boolean method similarTrees t.docx
Upcoming SlideShare
f + g + j f + g + h + i + j f + g i + h + g + f    The following figur.docxf + g + j f + g + h + i + j f + g i + h + g + f The following figur.docx
Loading in ... 3
1 of 1
Advertisement

More Related Content

More from rtodd432(20)

Advertisement

Extend the class BinaryTree to include a boolean method similarTrees t.docx

  1. Extend the class BinaryTree to include a boolean method similarTrees that determines whether the shapes of two trees are the same (the nodes do not have to contain the same values, but each node must have the same number of children) Solution public boolean similarTrees(treeNode r1, treeNode r2) { if (r1 == null && r2 == null){ return true; } if ((r1 == null && r2 != null) || (r1 != null && r2 == null)){ return false; } return similarTrees(r1.getLeftSon(), r2.getLeftSon()) && similarTrees(r1.getRightSon(), r2.getRightSon()); }
Advertisement