0x77964D4E (ntdll.dll)

问题遇到的现象和发生背景

中序和后序构建二叉树

用代码块功能插入代码,请勿粘贴截图
template <class ElemType>
void CreateBinaryTreeHelp(BinTreeNode *&r, ElemType pre[], ElemType in[], 
                            int preLeft, int preRight, int inLeft, int inRight)    
// 操作结果:已知二叉树的先序序列pre[preLeft..preRight]和中序序列in[inLeft..inRight]构造
//    以r为根的二叉树
{
    if (preLeft > preRight || inLeft > inRight)
    {    // 二叉树无结点,空二叉树
        r = NULL;                                    // 空二叉树根为空
    }
    else
    {    // 二叉树有结点,非空二叉树
        r = new BinTreeNode(pre[preLeft]);// 生成根结点
        int mid = inLeft;                            // mid为pre[preLeft]在in[]中的位置
        while (in[mid] != pre[preLeft]) 
        {    // 查找pre[preLeft]在in[]中的位置,也就是中序序列中根的位置
            mid++;
        }
        CreateBinaryTreeHelp(r->leftChild, pre, in, preLeft+1, preLeft + mid - inLeft, inLeft, mid - 1);
            // 生成左子树
        CreateBinaryTreeHelp(r->rightChild, pre, in, preLeft + mid - inLeft + 1, preRight, mid + 1, inRight);                                // 生成右子树
    }
} 


运行结果及报错内容

0x77964D4E (ntdll.dll) (实验2第6题.exe 中)处有未经处理的异常: 0xC00000FD: Stack overflow (参数: 0x00000001, 0x00602FFC)。