void BiTree2DuList(BSTreeNode *BST)
{
LinkStack S; BSTreeNode *p = NULL; BSTreeNode *q = NULL;
InitStack(S); p = BST;
while (p || !StackEmpty(S)) {
if (p) { Push(S, p); p = p->m_pLeft; }
else {
Pop(S, p);
if (q) q->m_pRight = p; p->m_pLeft = q; q = p; //中序遍历修改结点左右孩子指针
p = p->m_pRight;
}
}
}
{
LinkStack S; BSTreeNode *p = NULL; BSTreeNode *q = NULL;
InitStack(S); p = BST;
while (p || !StackEmpty(S)) {
if (p) { Push(S, p); p = p->m_pLeft; }
else {
Pop(S, p);
if (q) q->m_pRight = p; p->m_pLeft = q; q = p; //中序遍历修改结点左右孩子指针
p = p->m_pRight;
}
}
}