@@ -0,0 +1,1237 @@
+package com.practice.tree;%0Aimport java.util.Arrays;%0A%0A/**%0A * Print Right View of a Binary Tree  - http://www.geeksforgeeks.org/print-right-view-binary-tree-2/%0A * %0A * @author tsohil%0A *%0A */%0Apublic class PrintRightView %7B%0A%09public static int%5B%5D rightView;%0A%09public static int count = 0;%0A%09%0A%09public static void printRightView(Node root) %7B%0A%09%09if(root == null) %7B%0A%09%09%09System.out.println(%22NULL%22);%0A%09%09%7D%0A%09%09%0A%09%09if(root.right != null) %7B%0A%09%09%09printRightView(root.right);%0A%09%09%7D%0A%09%09%0A%09%09rightView%5Bcount++%5D = root.data;%0A%09%7D%0A%09%0A%09public static int depth(Node root) %7B%0A%09%09if(root == null) %7B%0A%09%09%09return 0;%0A%09%09%7D else %7B%0A%09%09%09return 1+depth(root.right);%0A%09%09%7D%0A%09%7D%0A%09%0A%09public static void main(String%5B%5D args) %7B%0A%09%09Node root = new Node(1);%0A%09%09root.left = new Node(2);%0A%09%09root.left.left = new Node(4);%0A%09%09root.left.right = new Node(5);%0A%09%09%0A%09%09root.right = new Node(3);%0A%09%09root.right.left = new Node(6);%0A%09%09root.right.right = new Node(7);%0A%09%09root.right.right.right = new Node(8);%0A%09%09%0A%09%09%0A%09%09rightView = new int%5Bdepth(root)%5D;%0A%09%09printRightView(root);%0A%09%09%0A%09%09//reverse array%0A%09%09for(int i=0; i%3CrightView.length/2; i++) %7B%0A%09%09%09int temp = rightView%5Bi%5D;%0A%09%09%09rightView%5Bi%5D = rightView%5BrightView.length - i - 1%5D;%0A%09%09%09rightView%5BrightView.length - i - 1%5D = temp;%0A%09%09%7D%0A%09%09%0A%09%09System.out.println(Arrays.toString(rightView));%0A%09%7D%0A%7D%0A

Print right view of Binary Tree