void BTreeToDoubleLinkList(Node *pRoot, Node *&pFirst, Node *&pLast) { if (!pRoot) { pFirst = NULL; pLast = NULL; return; } Node *pFirstLeft = NULL; Node *pLastLeft = NULL; Node *pFirstRight = NULL; Node *pLastRight = NULL; if (!pRoot->pLeft) pFirst = pRoot; else { BTreeToDoubleLinkList(pRoot->pLeft, pFirstLeft, pLastLeft); pFirst = pFirstLeft; pRoot->pLeft = pLastLeft; pLastLeft->pRight = pRoot; } if (!pRoot->pRight) pLast = pRoot; else { BTreeToDoubleLinkList(pRoot->pRight, pFirstRight, pLastRight); pLast = pLastRight; pRoot->pRight = pFirstLeft; pFirstRight->pLeft = pRoot; } }
EOF