traversal - Java - finding a parent of a node in a Binary Tree? (converted from a general tree) -
traversal - Java - finding a parent of a node in a Binary Tree? (converted from a general tree) -
i have binary tree converted general tree. meaning, left node of given node node's child, , right node of given node node's sibling.
my question - how can write method take node , find parent? (by traversing entire tree guess)
thanks!
this help you
private static binarynode getparent(anytype x, binarynode<anytype> t, binarynode<anytype> parent) { if (t == null) { homecoming null; } else { if (x.compareto(t.element) < 0) { homecoming getparent(x, t.left, t); } else if (x.compareto(t.element) > 0) { homecoming getparent(x, t.right, t); } else { homecoming parent; } } }
java traversal
Comments
Post a Comment