public static void flatten4(TreeNode root) {
    	if(root == null ){
    		return;
    	}
    	
    	Stack<TreeNode> toVisit= new Stack<TreeNode>();
    	TreeNode prev = null;
    	toVisit.push(root);
    	while(!toVisit.isEmpty()){
    		TreeNode cur = toVisit.pop();
    		if(cur.right != null) toVisit.push(cur.right);
    		if(cur.left != null) toVisit.push(cur.left);
    		if(prev != null) {
    			prev.left = null;
    			prev.right = cur;
    		}
    		prev = cur;
    	}
	}