public void flatten(TreeNode root) {
		TreeNode current = root;
		while(current != null){
			if(current.left != null){
				TreeNode curLeft = current.left;
				//find the last node for current left branch:
				while(curLeft.right != null || curLeft.left != null){
					if(curLeft.right == null && curLeft.left != null){
						curLeft = curLeft.left;
						continue;
					}
					curLeft = curLeft.right;
				}
				if(curLeft.left == null){
					curLeft.right = current.right;
				}
				current.right = current.left;
				current.left = null;
				current = current.right;
			}else{
				current = current.right;
			}
		}
	}