java - BST equality check -


i have method checks see if node of bst equal node of tree (given inside input) - regardless of structure.

this have far seems missing something.

public boolean samevalues(bstinterface<t> other)  {     if(other == null && != null)         return false;     else if(other.size() == 0 && this.size() == 0)         return true;      object temp = null;     object temp2 = null;     while(other.preorderiterator().hasnext() && this.preorderiterator().hasnext())     {         temp = other.preorderiterator().next();         temp2 = this.preorderiterator().next();          if(temp.equals(temp2))             return true;         else             return false;     }         return false; } 

does know better approach this? thanks.

your while() loop terminates in first iteration due superfluous return false. should rather like:

    while(other.preorderiterator().hasnext() && this.preorderiterator().hasnext())     {         temp = other.preorderiterator().next();         temp2 = this.preorderiterator().next();          if(temp.equals(temp2))    // same data found?             return true;          // return success         // else                   // not return! continue!         //    return false;     }         return false; } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -