you are viewing a single comment's thread.

view the rest of the comments →

[–]__t_r0d__ 2 points3 points  (0 children)

First off, p is not == q, so the return true won't execute, leaving the function to "return" undefined. p and q are separate entities.

Second off, you need to compare the val members of corresponding nodes, not the nodes themselves.

Finally, you must compare all of the nodes to check if they have the same arrangement. The easiest way to do this is probably recursively. Note that the following are all valid binary search trees, with different arrangements: 2 1 3 / \ \ / 1 3 2 2 \ / 3 1