判断一个数组是否为二叉树的后序遍历

bool IsTree(vector::iterator &begin,vector::iterator &end)
{
    if(distance(begin,end) == 1 || begin == end)
        return true;
    vector::iterator iter = end;
    --iter;
    vector::iterator it = find_if(begin,end,bind2nd(greater(),*iter));
    if(find_if(it,end,bind2nd(less(),*iter)) != end)
        return false;
    return IsTree(begin,it) && IsTree(it,iter);
}

你可能感兴趣的:(笔试题,C++)