@@ -0,0 +1,1346 @@
+package data_structures.trees;%0D%0A%0D%0A/*%0D%0A * You are given a pointer to the root of a binary tree. Print the top view of%0D%0A * the binary tree.%0D%0A * You only have to complete the function.%0D%0A * For example :%0D%0A * %0D%0A *       3%0D%0A *      / %5C%0D%0A *     5   2%0D%0A *    / %5C / %5C%0D%0A *   1  4 6  7%0D%0A *    %5C     /%0D%0A *     9   8%0D%0A * Top View : 1 -%3E 5 -%3E 3 -%3E 2 -%3E 7%0D%0A * %0D%0A * Input Format: %0D%0A * You are given a function,%0D%0A * %0D%0A * void top_view(node * root)%0D%0A * %7B%0D%0A * %0D%0A * %7D%0D%0A * %0D%0A * Output Format: %0D%0A * Print the values on a single line separated by space.%0D%0A * %0D%0A * Sample Input: %0D%0A *       3%0D%0A *      / %5C%0D%0A *     5   2%0D%0A *    / %5C / %5C%0D%0A *   1  4 6  7%0D%0A *    %5C     /%0D%0A *     9   8%0D%0A *     %0D%0A * Sample Output: %0D%0A * 1 5 3 2 7%0D%0A */%0D%0Apublic class TopView %7B%0D%0A%0D%0A%09void top_view(Node root) %7B%0D%0A%09    if (root == null) %7B%0D%0A%09        return;%0D%0A%09    %7D%0D%0A%09    %0D%0A%09    if (root.left != null) %7B%0D%0A%09        printLeftSide(root.left);%0D%0A%09    %7D%0D%0A%09    %0D%0A%09    System.out.print(root.data + %22 %22);%0D%0A%09    %0D%0A%09    if (root.right != null) %7B%0D%0A%09        printRightSide(root.right);%0D%0A%09    %7D%0D%0A%09%7D%0D%0A%0D%0A%09void printLeftSide(Node node) %7B%0D%0A%09    if (node.left != null) %7B%0D%0A%09        printLeftSide(node.left);%0D%0A%09    %7D%0D%0A%09    System.out.print(node.data + %22 %22);%0D%0A%09%7D%0D%0A%0D%0A%09void printRightSide(Node node) %7B%0D%0A%09    System.out.print(node.data + %22 %22);%0D%0A%09    if (node.right != null) %7B%0D%0A%09        printRightSide(node.right);%0D%0A%09    %7D%0D%0A%09%7D%0D%0A%7D

Add TopView