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

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -