@@ -0,0 +1,1807 @@
+package geeksforgeeks;%0D%0A%0D%0Aimport geeksforgeeks._01DataStructures_BinaryTree_00.Node;%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A/*%0D%0A * http://www.geeksforgeeks.org/remove-all-nodes-which-lie-on-a-path-having-sum-less-than-k/%0D%0A * Remove all nodes which dont lie in any path with sum%3E= k%0D%0A * %0D%0A */;%0D%0A public class _01DataStructures_BinaryTree_46 %7B%0D%0A%09 public static void main(String%5B%5D args) %7B%0D%0A%09%09 _01DataStructures_BinaryTree_00 binaryTree1=new _01DataStructures_BinaryTree_00();%0D%0A%09%09 binaryTree1.insert(null,null,1);%0D%0A%09%09 binaryTree1.insert(1,%22left%22,2);%0D%0A%09%09 binaryTree1.insert(1,%22right%22,3);%0D%0A%09%09 binaryTree1.insert(2,%22left%22,4);%0D%0A%09%09 binaryTree1.insert(2,%22right%22,5);%0D%0A%09%09 binaryTree1.insert(3,%22left%22,6);%0D%0A%09%09 binaryTree1.insert(3,%22right%22,7);%0D%0A%09%09 binaryTree1.insert(4,%22left%22,8);%0D%0A%09%09 binaryTree1.insert(4,%22right%22,9);%0D%0A%09%09 binaryTree1.insert(5,%22left%22,12);%0D%0A%09%09 binaryTree1.insert(7,%22left%22,10);%0D%0A%09%09 binaryTree1.insert(9,%22left%22,13);%0D%0A%09%09 binaryTree1.insert(9,%22right%22,14);%0D%0A%09%09 binaryTree1.insert(10,%22right%22,11);%0D%0A%09%09 binaryTree1.insert(14,%22left%22,15);%0D%0A%09%09 binaryTree1.preOrder();%0D%0A%09%09 Node outputNode=deleteNodeSum(binaryTree1,14);%0D%0A%09%09 preOrder(outputNode);%0D%0A%09 %7D%0D%0A%0D%0A%09 private static void preOrder(Node node) %7B%0D%0A%09%09 if(node!=null)%0D%0A%09%09 %7B%0D%0A%09%09%09 preOrder(node.left);%0D%0A%09%09%09 preOrder(node.right);%0D%0A%09%09%09 System.out.print(node.data+%22,%22);%0D%0A%09%09 %7D%0D%0A%0D%0A%09 %7D%0D%0A%0D%0A%09 private static Node deleteNodeSum(%0D%0A%09%09%09 _01DataStructures_BinaryTree_00 binaryTree1, int k) %7B%0D%0A%09%09 return deleteNodeSum(binaryTree1.rootNode,k,0);%0D%0A%09 %7D%0D%0A%0D%0A%09 private static Node deleteNodeSum(Node node, int k, int sum) %7B%0D%0A%09%09 if(node==null)%0D%0A%09%09%09 return null;%0D%0A%09%09 int leftSum=sum+node.data;%0D%0A%09%09 int rightSum=leftSum;%0D%0A%09%09 node.left=deleteNodeSum(node.left,k,leftSum);%0D%0A%09%09 node.right=deleteNodeSum(node.right,k,rightSum);%0D%0A%09%09 sum=(leftSum%3ErightSum)?leftSum:rightSum;%0D%0A%09%09 if(sum%3Ek)%0D%0A%09%09%09 node=null;%0D%0A%09%09 return node;%0D%0A%09 %7D%0D%0A %7D%0D%0A

remove nodes with path sum >k completed