public void flatten(TreeNode root) {
        if(root == null)
            return;        
        
        TreeNode left = root.left;
        TreeNode right = root.right;
        
        previous = root;
        flatten(left);
        if(previous != root){
            previous.right = right;
            root.right = left;
            root.left = null;            
        }        
        flatten(right);
    }