对于一个排序数组,创建最低高度的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

posted on 2012-12-09 14:01  kkmm  阅读(169)  评论(0编辑  收藏  举报