You are viewing a single comment's thread. Return to all comments →
My recursive solution. Like you're standing on the spine of a house roof. Look left, look down, look right.
void top_view(Node root) { left_view(root.left); System.out.print(root.data + " "); right_view(root.right); } void left_view(Node root) { if (root == null) return; left_view(root.left); System.out.print(root.data + " "); } void right_view(Node root) { if (root == null) return; System.out.print(root.data + " "); right_view(root.right); }
Seems like cookies are disabled on this browser, please enable them to open this website
Tree : Top View
You are viewing a single comment's thread. Return to all comments →
My recursive solution. Like you're standing on the spine of a house roof. Look left, look down, look right.