java - Compare two binary trees to see if they have the same structure -


another easy 1 can't seem it. need write method compares structures of 2 binary trees , returns weather same or not. data , data types not important structures. here examples:

examples!

here code have far. think close.

public boolean samestructure(orderedset<e> other) {     if (other.size() != size)         return false;     return samestructurehelp(other, root, other.root); }  private boolean samestructurehelp(orderedset<e> other, treenode ref,         treenode otherref) {     if (otherref == null && ref != null)         return false;     if (otherref != null && ref == null)         return false;     samestructurehelp(other, ref.left, otherref.left);     samestructurehelp(other, ref.right, otherref.right);     return true;  } 

what pasted right, missing critical piece: instead of checking left , right subtrees, should return and value, mean if trees rooted in current nodes satisfies condition being same stucture.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -