对于一个排序数组,创建最低高度的Binary Tree
Cracking Interview 4-3:
struct Node{ int value; Node *pLeft; Node *pRight; }; Node *CreateBTree(int arr[], int begin, int end) { if (!arr || (begin > end)) return NULL; Node *pNode = new Node(); int mid = (begin + end)/2; pNode->value = arr[mid]; pNode->pLeft = CreateBTree(arr, begin, mid-1); pNode->pRight = CreateBTree(arr, mid+1, end); return pNode; }
EOF