package GeeksforGeeksPractice;

public class _0010ConvertBinaryTreeToChildSumTree {
	public static class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;
		TreeNode(int x) { val = x; }
	}
	public static void main(String args[]){
		TreeNode tn=new TreeNode(50);
		tn.left=new TreeNode(8);
		tn.right=new TreeNode(2);
		tn.left.left=new TreeNode(3);
		tn.left.right=new TreeNode(5);
		tn.right.left=new TreeNode(1);
		tn.right.right=new TreeNode(30);
		preOrder(tn);System.out.println();
		modifyChildSumProperty(tn);
		preOrder(tn);System.out.println();
		//50/8/3/5/2/1/30/
		//50/19/14/5/31/1/30/

	}
	private static void preOrder(TreeNode tn) {
		if(tn!=null)
		{
			System.out.print(tn.val+"/");
			preOrder(tn.left);
			preOrder(tn.right);			
		}

	}
	private static void modifyChildSumProperty(TreeNode tn) {
		
	}

}

@@ -543,32 +543,36 @@
 %0A%09%09preOrder(tn);
+%0D%0A%09%09
 System.out.print
@@ -578,16 +578,16 @@
 tln();%0D%0A
-
 %09%09//50/8
@@ -846,25 +846,636 @@
 reeNode tn) 
-%7B
+%0D%0A%09%7B%0D%0A%09%09if(tn!=null)%0D%0A%09%09%7B%0D%0A%09%09%09modifyChildSumProperty(tn.left);%0D%0A%09%09%09modifyChildSumProperty(tn.right);%0D%0A%09%09%09int leftVal=0,rightVal=0;%0D%0A%09%09%09if(tn.left!=null)%0D%0A%09%09%09%09leftVal=tn.left.val;%0D%0A%09%09%09if(tn.right!=null)%0D%0A%09%09%09%09rightVal=tn.right.val;%0D%0A%09%09%09int diff=leftVal+rightVal-tn.val;%0D%0A%09%09%09if(diff%3E0)%0D%0A%09%09%09%7B%0D%0A%09%09%09%09tn.val=tn.val+diff;%0D%0A%09%09%09%7D%0D%0A%09%09%09if(diff%3C0)%0D%0A%09%09%09%7B%0D%0A%09%09%09%09increment(tn,-diff);%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%0D%0A%09%7D%0D%0A%09private static void increment(TreeNode tn, int diff) %7B%0D%0A%09%09if(tn.left!=null)%0D%0A%09%09%7B%0D%0A%09%09%09tn.left.val+=diff;%0D%0A%09%09%09increment(tn.left, diff);%0D%0A%09%09%7Delse if(tn.right!=null)%0D%0A%09%09%7B%0D%0A%09%09%09tn.right.val+=diff;%0D%0A%09%09%09increment(tn.right, diff);%0D%0A%09%09%7D
 %0D%0A%09%09%0D%0A%09%7D%0D%0A%0D%0A

convert binary tree to child sum tree redo completed