void CObBinTree::InOrderVisit(CObBinTree::CNode* pNode) { ASSERT( m_pfnVisit!=NULL ); if( m_bTvStop )return; if( pNode->pLChild )InOrderVisit( pNode->pLChild ); if( !(*m_pfnVisit)(pNode->data, m_lpTvParam) )m_bTvStop=TRUE; if( pNode->pRChild )InOrderVisit( pNode->pRChild ); }
void CObBinTree::WalkTree( CObBinTree::TV_FUNC pfnVisit, LPVOID lpParam, int nTvOrder ) { ASSERT( pfnVisit!=NULL ); if( IsEmpty() )return; m_lpTvParam = lpParam; m_pfnVisit = pfnVisit; m_bTvStop = FALSE; ASSERT( m_pNodeRoot!=NULL ); switch(nTvOrder){ case TV_PREORDER: PreOrderVisit(m_pNodeRoot); break; case TV_INORDER: InOrderVisit(m_pNodeRoot); break; case TV_POSTORDER: PostOrderVisit(m_pNodeRoot); break; default: ASSERT(FALSE); } m_lpTvParam = NULL; m_pfnVisit = NULL; m_bTvStop = FALSE; }
int main() { BiTree T; CreateTree(T); printf("Visit Tree in PreOrder :\n"); PreOrderVisit(T, VisitData); putchar('\n'); printf("Visit Tree in InOrder :\n"); InOrderVisit(T, VisitData); putchar('\n'); printf("Visit Tree in PostOrder :\n"); PostOrderVisit(T, VisitData); putchar('\n'); return 0; }
void BST < Filler > :: InOrderVisit ( NODO < Filler > * Nodo ){ //Se esiste l'Albero e c'è almeno un nodo if ( this && Nodo ){ //Se esiste il sinisto if ( Nodo->GetLeft () ){ //Vai a sinistra InOrderVisit ( Nodo->GetLeft () ); } else{ std :: cout << "*" << std :: endl; } //Stampa il nodo Nodo->PrintNODO (); if ( Nodo->GetRight () ){ InOrderVisit ( Nodo->GetRight () ); } else{ std :: cout << "*" << std :: endl; } } else{ std :: cout << "*" << std :: endl; } }