@@ -0,0 +1,1951 @@
+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/convert-an-arbitrary-binary-tree-to-a-tree-that-holds-children-sum-property/%0D%0A * Convert an arbitrary Binary Tree to a tree that holds Children Sum Property%0D%0A * Question: Given an arbitrary binary tree, convert it to a binary tree that holds%0D%0A * Children Sum Property. You can only increment data values in any node%0D%0A * (You cannot change structure of tree and cannot decrement value of any node).%0D%0A */;%0D%0A public class _01DataStructures_BinaryTree_12 %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,50);%0D%0A%09%09 binaryTree1.insert(50,%22left%22,7);%0D%0A%09%09 binaryTree1.insert(50,%22right%22,2);%0D%0A%09%09 binaryTree1.insert(7,%22left%22,3);%0D%0A%09%09 binaryTree1.insert(7,%22right%22,5);%0D%0A%09%09 binaryTree1.insert(2,%22left%22,1);%0D%0A%09%09 binaryTree1.insert(2,%22right%22,30);%0D%0A%09%09 binaryTree1.preOrder();%0D%0A%09%09 convertTree(binaryTree1);%0D%0A%09%09 binaryTree1.preOrder();%0D%0A%09 %7D%0D%0A%0D%0A%09 private static void convertTree(%0D%0A%09%09%09 _01DataStructures_BinaryTree_00 binaryTree1) %7B%0D%0A%09%09 convertTree(binaryTree1.rootNode);%0D%0A%09 %7D%0D%0A%0D%0A%09 private static void convertTree(Node node) %7B%0D%0A%0D%0A%09%09 int leftData=0,rightData=0,diff;%0D%0A%09%09 if(node!=null)%7B%0D%0A%09%09%09 convertTree(node.left);%0D%0A%09%09%09 convertTree(node.right);%0D%0A%09%09%09 if(node.left==null)%0D%0A%09%09%09%09 leftData=0;%0D%0A%09%09%09 else%0D%0A%09%09%09%09 leftData=node.left.data;%0D%0A%09%09%09 if(node.right==null)%0D%0A%09%09%09%09 rightData=0;%0D%0A%09%09%09 else%0D%0A%09%09%09%09 rightData=node.right.data;%0D%0A%09%09%09 diff=leftData+rightData-node.data;%0D%0A%09%09%09 if(diff%3E0)%7B%0D%0A%09%09%09%09 node.data+=diff;%0D%0A%09%09%09 %7D%0D%0A%09%09%09 else if(diff%3C0)%7B%0D%0A%09%09%09%09 increment(node,-diff);%0D%0A%09%09%09 %7D%0D%0A%0D%0A%09%09 %7D%0D%0A%0D%0A%09 %7D%0D%0A%0D%0A%09private static void increment(Node node, int diff) %7B%0D%0A%09%09if(node.left!=null)%7B%0D%0A%09%09%09node.left.data+=diff;%0D%0A%09%09%09increment(node.left,diff);%0D%0A%09%09%7D%0D%0A%09%09else if(node.right!=null)%7B%0D%0A%09%09%09node.right.data+=diff;%0D%0A%09%09%09increment(node.right,diff);%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%7D%0D%0A%0D%0A%0D%0A %7D

change tree to govern tree sum property