TBS_tpCondRet TBS_ExcluirSimbolo( TBS_tppTabela pTabela , char * pSimbolo ) { unsigned inxHash ; tpLista * pElem ; #ifdef _DEBUG TST_ASSERT( pTabela != NULL ) ; TST_ASSERT( pSimbolo != NULL ) ; #endif pElem = ProcurarSimbolo( pTabela , pSimbolo , &inxHash ) ; if ( pElem == NULL ) { return TBS_CondRetSimboloNaoExiste ; } /* if */ if ( pElem->pProx != NULL ) { pElem->pProx->pAnt = pElem->pAnt ; } /* if */ if ( pElem->pAnt != NULL ) { pElem->pAnt->pProx = pElem->pProx ; } else { pTabela->pVtHash[ inxHash ] = pElem->pProx ; } /* if */ LiberarElemento( pTabela , pElem ) ; return TBS_CondRetOK ; } /* Fim função: TBS &Excluir símbolo */
LIS_tpCondRet LIS_EsvaziarLista(LIS_tppLista pLista) { tpElemLista * pElem; tpElemLista * pProx; #ifdef _DEBUG assert(pLista != NULL); #endif if (pLista == NULL) { return LIS_CondRetListaNaoExiste; } /* if */ pElem = pLista->pOrigemLista; while (pElem != NULL) { pProx = pElem->pProx; LiberarElemento(pLista, pElem); pElem = pProx; } /* while */ pLista->pOrigemLista = NULL; pLista->pFimLista = NULL; pLista->pElemCorr = NULL; pLista->numElem = 0; return LIS_CondRetOK; } /* Fim função: LIS &Esvaziar lista */
void TBS_DestruirTabela( TBS_tppTabela pTabela ) { unsigned inxElem ; tpLista * pElem ; tpLista * pProx ; #ifdef _DEBUG TST_ASSERT( pTabela != NULL ) ; #endif for ( inxElem = 0 ; inxElem < pTabela->tamVtHash ; inxElem++ ) { /* Destruir todos elementos de lista de colisão */ pElem = pTabela->pVtHash[ inxElem ] ; while ( pElem != NULL ) { pProx = pElem->pProx ; LiberarElemento( pTabela , pElem ) ; pElem = pProx ; } /* while */ } /* fim repete: Raiz de TBS &Destruir tabela de símbolos */ free( pTabela->pVtHash ) ; free( pTabela ) ; } /* Fim função: TBS &Destruir tabela de símbolos */
LIS_tpCondRet LIS_EsvaziarLista( LIS_tppLista lista ) { tpElemLista * pElem ; tpElemLista * pProx ; #ifdef _DEBUG assert( lista != NULL ) ; CNT_CONTAR( "LIS_EsvaziarLista" ) ; #endif pElem = lista->pOrigemLista ; while ( pElem != NULL ) { #ifdef _DEBUG CNT_CONTAR( "LIS_EsvaziarLista_while" ) ; #endif pProx = pElem->pProx ; LiberarElemento( lista , pElem ) ; pElem = pProx ; } /* while */ LimparCabeca( lista ) ; return LIS_CondRetOK; } /* Fim função: LIS &Esvaziar lista */
void LIS_EsvaziarLista( LIS_tppLista pLista ) { tpElemLista * pElem ; tpElemLista * pProx ; #ifdef _DEBUG assert( pLista != NULL ) ; #endif #ifdef _DEBUG CNT_CONTAR( "EsvaziarLista" ) ; #endif pElem = pLista->pOrigemLista ; while ( pElem != NULL ) { #ifdef _DEBUG CNT_CONTAR( "EsvaziarListaWhile" ) ; #endif pProx = pElem->pProx ; LiberarElemento( pLista , pElem ) ; pElem = pProx ; } /* while */ LimparCabeca( pLista ) ; } /* Fim função: LIS &Esvaziar lista */
LIS_tpCondRet LIS_ExcluirElemento( LIS_tppLista lista ) { tpElemLista * pElem ; #ifdef _DEBUG assert( lista != NULL ) ; #endif if ( lista->pElemCorr == NULL ) { #ifdef _DEBUG CNT_CONTAR( "LIS_ExcluirElemento_Vazia" ) ; #endif return LIS_CondRetListaVazia ; } /* if */ pElem = lista->pElemCorr ; /* Desencadeia à esquerda */ if ( pElem->pAnt != NULL ) { #ifdef _DEBUG CNT_CONTAR( "LIS_ExcluirElemento_Ant" ) ; #endif pElem->pAnt->pProx = pElem->pProx ; lista->pElemCorr = pElem->pAnt ; } else { #ifdef _DEBUG CNT_CONTAR( "LIS_ExcluirElemento_AntNULL" ) ; #endif lista->pElemCorr = pElem->pProx ; lista->pOrigemLista = lista->pElemCorr ; } /* if */ /* Desencadeia à direita */ if ( pElem->pProx != NULL ) { #ifdef _DEBUG CNT_CONTAR( "LIS_ExcluirElemento_Prox" ) ; #endif pElem->pProx->pAnt = pElem->pAnt ; } else { #ifdef _DEBUG CNT_CONTAR( "LIS_ExcluirElemento_ProxNULL" ) ; #endif lista->pFimLista = pElem->pAnt ; } /* if */ LiberarElemento( lista , pElem ) ; return LIS_CondRetOK ; } /* Fim função: LIS &Excluir elemento */
LIS_tpCondRet LIS_ExcluirElemento( LIS_tppLista pLista ) { tpElemLista * pElem ; #ifdef _DEBUG assert( pLista != NULL ) ; #endif #ifdef _DEBUG CNT_CONTAR( "ExcluirElemento" ) ; #endif if ( pLista->pElemCorr == NULL ) { return LIS_CondRetListaVazia ; } /* if */ pElem = pLista->pElemCorr ; /* Desencadeia à esquerda */ if ( pElem->pAnt != NULL ) { pElem->pAnt->pProx = pElem->pProx ; pLista->pElemCorr = pElem->pAnt ; #ifdef _DEBUG CNT_CONTAR( "ExcluirElementoif0" ) ; #endif } else { pLista->pElemCorr = pElem->pProx ; pLista->pOrigemLista = pLista->pElemCorr ; #ifdef _DEBUG CNT_CONTAR( "ExcluirElementoelse0" ) ; #endif } /* if */ /* Desencadeia à direita */ if ( pElem->pProx != NULL ) { pElem->pProx->pAnt = pElem->pAnt ; #ifdef _DEBUG CNT_CONTAR( "ExcluirElementoif1" ) ; #endif } else { pLista->pFimLista = pElem->pAnt ; #ifdef _DEBUG CNT_CONTAR( "ExcluirElementoelse1" ) ; #endif } /* if */ LiberarElemento( pLista , pElem ) ; return LIS_CondRetOK ; } /* Fim função: LIS &Excluir elemento */
LIS_tpCondRet LIS_EsvaziarLista ( LIS_tppLista * pLista ) { tpElemLista * pElem ; /* Tratar lista inexistente */ if ( pLista == NULL ) { return LIS_CondRetListaInexistente; } /* if */ /* fim ativa: Tratar lista inexistente */ /* Tratar lista vazia */ if ( (*pLista)->pOrigemLista == NULL ) { return LIS_CondRetListaVazia; } /* if */ /* fim ativa: Tratar lista vazia */ if( (*pLista)->numElem == 0 ) { (*pLista)->pElemCorr = NULL; LimparCabeca( (*pLista) ) ; return LIS_CondRetOK; } (*pLista)->pElemCorr = (*pLista)->pOrigemLista ; while ( (*pLista)->pElemCorr != NULL ) { pElem = (*pLista)->pElemCorr; (*pLista)->pElemCorr = (*pLista)->pElemCorr->pProx; LiberarElemento( pElem, (*pLista)->ExcluirValor ) ; } /* while */ (*pLista)->pElemCorr = NULL; LimparCabeca( (*pLista) ) ; return LIS_CondRetOK; } /* Fim função: LIS &Esvaziar lista */
LIS_tpCondRet LIS_ExcluirElemento( LIS_tppLista pLista ) { tpElemLista * pElem ; if ( pLista == NULL ) /* Lista não existe */ { return LIS_CondRetListaNaoExiste; } /* if */ if ( pLista->pElemCorr == NULL ) /* Lista vazia */ { return LIS_CondRetListaVazia ; } /* if */ pElem = pLista->pElemCorr ; /* Desencadeia à esquerda */ if ( pElem->pAnt != NULL ) { pElem->pAnt->pProx = pElem->pProx ; pLista->pElemCorr = pElem->pAnt ; } else { pLista->pElemCorr = pElem->pProx ; pLista->pOrigemLista = pLista->pElemCorr ; } /* if */ /* Desencadeia à direita */ if ( pElem->pProx != NULL ) { pElem->pProx->pAnt = pElem->pAnt ; } else { pLista->pFimLista = pElem->pAnt ; } /* if */ LiberarElemento( pLista , pElem ) ; return LIS_CondRetOK ; } /* Fim função: LIS &Excluir elemento */
void LIS_EsvaziarLista( LIS_tppLista pLista ) { LIS_tpElemLista *pElem ; LIS_tpElemLista *pProx ; #ifdef _DEBUG assert( pLista != NULL ) ; #endif pElem = pLista->pOrigemLista ; while ( pElem != NULL ) { pProx = pElem->pProx ; LiberarElemento( pLista , pElem ) ; pElem = pProx ; } /* while */ LimparCabeca( pLista ) ; } /* Fim funcao: LIS &Esvaziar lista */
LIS_tpCondRet LIS_EsvaziarLista( LIS_tppLista pLista ) { tpElemLista * pElem ; tpElemLista * pProx ; if ( pLista == NULL ) /* Lista não existe */ { return LIS_CondRetListaNaoExiste; }/* if */ pElem = pLista->pOrigemLista ; while ( pElem != NULL ) { pProx = pElem->pProx ; LiberarElemento( pLista , pElem ) ; pElem = pProx ; } /* while */ LimparCabeca( pLista ) ; return LIS_CondRetOK; } /* Fim função: LIS &Esvaziar lista */
/********** Fim do módulo de implementação: LIS Lista duplamente encadeada **********/ void DeturpaLista ( LIS_tppLista pLista, LIS_ModosDeturpacao Deturpacao) { LIS_tpLista * Lista = NULL; if(pLista == NULL) return; Lista = (LIS_tpLista*)(pLista); switch (Deturpacao) { /* Elimina o nó corrente da estrutura */ case DeturpaEliminaCorr : { lixo = ( tpElemLista * ) malloc( sizeof( tpElemLista )) ; lixo->pAnt = NULL; lixo->pProx = NULL; lixo->pValor = NULL; lixo->listaCabeca = Lista; Lista->pElemCorr->pAnt->pProx = lixo; Lista->pElemCorr->pProx->pAnt = lixo; LiberarElemento(Lista, Lista->pElemCorr); break; } /* Anula o ponteiro para o próximo elemento da estrutura */ case DeturpaPtProxNulo : { Lista->pElemCorr->pProx = NULL; break; } /* Anula o ponteiro para o elemento anterior */ case DeturpaPtAntNulo : { Lista->pElemCorr->pAnt = NULL; break; } /* Atribui Lixo para o ponteiro do próximo elemento */ case DeturpaPtProxLixo: { lixo = ( tpElemLista * ) malloc( sizeof( tpElemLista )) ; lixo->pAnt = NULL; lixo->pProx = NULL; lixo->pValor = NULL; lixo->listaCabeca = Lista; Lista->pElemCorr->pProx = lixo; break; } /* Atribui Lixo para o ponteiro para o elemento anterior */ case DeturpaPtAntLixo : { lixo = ( tpElemLista * ) malloc( sizeof( tpElemLista )) ; lixo->pAnt = NULL; lixo->pProx = NULL; lixo->pValor = NULL; lixo->listaCabeca = Lista; Lista->pElemCorr->pAnt = lixo; break; } /* Atribui Nulo ao conteúdo do nó corrente */ case DeturpaPtConteudoCorrNulo : { Lista->pElemCorr->pValor = NULL; break; } /* Modifica o tipo de espaço de dados do nó corrente */ case DeturpaTipoCorr : { CED_DefinirTipoEspaco( Lista->pElemCorr , CED_ID_TIPO_VALOR_NULO ) ; break; } /* Elimina o elemento corrente sem usar free() */ case DeturpaEliminaSemFree : { LIS_DesencadeiaSemFree(Lista); break; } /* Atribui Nulo ao elemento corrente */ case DeturpaPtCorrNulo : { Lista->pElemCorr = NULL; break; } /* Atribui nulo ao ponteiro de origem da estrutura */ case DeturpaPtOrigemNulo : { Lista->pOrigemLista = NULL; break; } /* Altera o tipo de espaço da cabeça de lista*/ case DeturpaTipoCabeca : { CED_DefinirTipoEspaco(Lista , CED_ID_TIPO_VALOR_NULO ) ; break; } default: break; } /* Fim Switch Deturpacao */ }