递归 BSTreeNode* InOrderAndDisplay(BSTreeNode* pTreeHeader, int nValue) { BSTreeNode* pRetValue = NULL; BSTreeNode* pCurrent = pTreeHeader; if(pCurrent->m_pLeft != NULL) pRetValue = InOrderAndDisplay(pCurrent->m_pLeft, nValue); if(nValue == pCurrent->m_nValue) return pCurrent; else if(NULL != pRetValue) // Do not need to search in right children if already found; return pRetValue; if(pCurrent->m_pRight != NULL) pRetValue = InOrderAndDisplay(pCurrent->m_pRight, nValue); return pRetValue; } 非递归 BSTreeNode* InOrderAndDisplay(BSTreeNode* pTreeHeader, int nValue) { BSTreeNode* pCurrent = pTreeHeader; vector<BSTreeNode*> stack; while(pCurrent!=NULL || !stack.empty()) { while(pCurrent != NULL) { stack.push_back(pCurrent); pCurrent = pCurrent->m_pLeft; } pCurrent = stack.back(); stack.pop_back(); if(pCurrent->m_nValue == nValue) return pCurrent; else pCurrent = pCurrent->m_pRight; } }