您的位置:首页 > 其它

给定有序数组,创建高度最小的二叉查找树

2015-08-22 19:59 260 查看




TreeNode createMinimalBST(int arr[], int start, int end)

{

if (end < start)

{

return null;

}

int mid = start + (end - start) / 2;

TreeNode n=new TreeNode(arr[mid]);

n.left=createMinimalBST(arr,start,mid-1);

n.right=createMinimalBST(arr,mid+1,end);

return n;

}

TreeNode createMinimalBST(int array[])

{

return createMinimalBST(array,0,array.length-1);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: