public static TreeNode preorder(TreeNode root) {
    	if (null != root) {
    		if (null == root.left && null == root.right) return root; 
    		TreeNode right = root.right;
    		TreeNode leftend = null;
    		if (null != root.left) {
    			leftend = preorder(root.left);
    			root.right = root.left;
    			root.left = null;
    		}
    		TreeNode rightend = preorder(right);
    		if (null != leftend) {
    			leftend.right = right;
    		} 
    		if (null != rightend) {
    			return rightend;
    		} else if (null != leftend) {
    			return leftend;
    		} else {
    			return rightend;
    		}
    	}
    	return null;
    }