/***************************************************************************
*  Função: GRA Destruir aresta adjacente
******/
GRA_tpCondRet GRA_DestruirArestaAdjacente(GRA_tppGrafo pGrafoParm, char *nomeAresta)
{
	tpGrafo *pGrafo = NULL;
	tpAresta *pAresta = NULL;
	GRA_tpCondRet graCondRet;

	if (pGrafoParm == NULL)
	{
		return GRA_CondRetGrafoNaoFoiCriado;
	}

	pGrafo = (tpGrafo*) pGrafoParm;

	if (EstaVazio(pGrafo))
	{
		return GRA_CondRetGrafoVazio;
	}

	// Busca Aresta à remover
   graCondRet = ProcurarAresta(pGrafo->pCorrente, nomeAresta, &pAresta);
   if (graCondRet != GRA_CondRetOK)
   {
      return GRA_CondRetNaoAchou;
   }

	// Remove referência do vértice corrente
	LIS_IrInicioLista(pAresta->pVertice->pAntecessores);
	LIS_ProcurarValor(pAresta->pVertice->pAntecessores,pGrafo->pCorrente->nome);

	LIS_ExcluirElemento(pAresta->pVertice->pAntecessores);
	LIS_ExcluirElemento(pGrafo->pCorrente->pSucessores);

	return GRA_CondRetOK;
}
Exemple #2
0
MTZ_tpCondRet MTZ_DestruirMatriz ( LIS_tppLista Tab )
{
	
	LIS_tppLista Col;
	PLH_tppPilha p;

	while ( Tab != NULL) {
			
			IrFinalLista( Tab );
			Col = (LIS_tppLista) LIS_ObterValor( Tab );
			
		while (Col != NULL) {
				IrFinalLista( Col );
				p = (PLH_tppPilha) LIS_ObterValor( Col );
				PLH_Libera( p );
				LIS_ExcluirElemento( Col );
				IrInicioLista( Col );			
		}

			LIS_ExcluirElemento( Tab );
			IrInicioLista( Tab );
	}		

		free ( Tab );

		return MTZ_CondRetOK;
}
Exemple #3
0
void GRA_DelNode (Graph *g)
{
	Node *n;
#ifdef _DEBUG
	int nOfNodesAntigo = g->nOfNodes;
	AssertGraph(g);
#endif /* _DEBUG */

    CNT_CONTAR("GRA_delNode - Inicializao");
	assert(g->currentNode);
	n = (Node *) LIS_ObterValor(g->currentNode);
	assert( n!=NULL );
#ifdef _DEBUG
	AssertNode(n,g);
#endif /* _DEBUG */

    CNT_CONTAR("GRA_delNode - Deletando no");
	delNode(g,n);
	LIS_ExcluirElemento(g->nodes);
	g->currentNode = LIS_ObterValor(g->nodes);
#ifdef _DEBUG
	g->nOfNodes--;
	assert ( g->nOfNodes == (nOfNodesAntigo - 1) );
	AssertGraph(g);
#endif /* _DEBUG */
}
Exemple #4
0
/* Essa funcao e' responsavel por criar e compor 2 links ligando
 * 2 nos.
 */
enum GRA_Ret linkTwoNodes(Node *node1, Node *node2)
{
	Link *link1, *link2, *link;
	IrInicioLista(node1->links);
	CNT_CONTAR("linkTwoNodes - Inicializacao");
	do{ /* Assertiva: Nao repetir links */
	    CNT_CONTAR("linkTwoNodes - Procurando link igual");
		link = LIS_ObterValor(node1->links);
		if( link && link->n2 == node2 ){
            CNT_CONTAR("linkTwoNodes - Links iguais");
			return GRA_InvalidLink;
		}
	}while (LIS_CondRetOK == LIS_AvancarElementoCorrente (node1->links,1));

    CNT_CONTAR("linkTwoNodes - Compondo Links");
	link1 = (Link*) malloc (sizeof(Link));
	if (!link1){
	CNT_CONTAR("linkTwoNodes - Alocacao de link1 falhou");
		return GRA_MemoryError;
	}
	link2 = (Link*) malloc (sizeof(Link));
	if (!link2){
		/* Muito improvavel de cair aqui num teste
	CNT_CNTAR("linkTwoNodes - Alocacao de link2 falhou"); */
		free (link1);
		return GRA_MemoryError;
	}

	/* Compoe os dois links */
	link1->n1 = node1;
	link1->n2 = node2;
	link1->brother = link2;
	link2->n1 = node2;
	link2->n2 = node1;
	link2->brother = link1;

	IrFinalLista(node1->links);
	IrFinalLista(node2->links);

	/* Tenta inserir cada link em uma lista, limpa se nao der certo */

	CNT_CONTAR("linkTwoNodes - Inserindo link 1 na lista");
	if( LIS_CondRetOK != LIS_InserirElementoApos(node1->links, link1) ){
        CNT_CONTAR("linkTwoNodes - Nao inseriu link 1 na lista");
		return GRA_MemoryError;
    }

    CNT_CONTAR("linkTwoNodes - Inserindo link 2 na lista");
	if( LIS_CondRetOK != LIS_InserirElementoApos(node2->links, link2) ){
        CNT_CONTAR("linkTwoNodes - Nao inseriu link 2 na lista");
		LIS_ExcluirElemento(node1->links);
		return GRA_MemoryError;
	}
#ifdef _DEBUG
	AssertLink(link1);
	AssertLink(link2);
#endif /* _DEBUG */
    CNT_CONTAR("linkTwoNodes - Finalizando");
	return GRA_Ok;
}
   PIL_tpCondRet PIL_PopCarta( PIL_tppPilha pPilha , CAR_tppCarta * pCarta )
   {
	    int valor ;
		char naipe ;
		PIL_tpCondRet condRet = PIL_VerCarta( pPilha , pCarta , 0 ) ;
        
        *pCarta = NULL ;
        
		if ( condRet != PIL_CondRetOK )
		{
			return condRet ;
		}

		CAR_ObterNaipe( *pCarta, &naipe );
		CAR_ObterValor( *pCarta, &valor );

		LIS_ExcluirElemento( pPilha->pListaCartas ); 

		/*LIS_ExcluirElemento irá destruir a carta junto do nó.
			 É necessário que ela seja criada novamente*/
		CAR_CriarCarta( pCarta ) ;
		CAR_PreencheCarta( *pCarta , naipe, valor ) ;

		return PIL_CondRetOK ; 	

   }/* Fim função: PIL Pop Carta */
Exemple #6
0
void* FIL_retiraElem (FIL_tppFila fila)
{
	//assertiva de entrada: fila não está vazia!!!!!
	void* pValor;
	LIS_IrInicioLista(fila->lista);
	LIS_ObterValor( fila->lista , &pValor);
	LIS_ExcluirElemento(fila->lista);
	return pValor;
}
Exemple #7
0
    static GRA_tpCondRet ExcluirVertice (GRA_tppGrafo pGrafo, tpVertice* pVertice) {
        tpAresta** vizinhos = NULL;
        tpNode* no = NULL;
        tpVertice * pVerticeVizinho = NULL;
        int i = 0;
        
        no = pVertice->pNode;
        LIS_IrInicioLista(pGrafo->componentes);
        LIS_ProcurarValor(pGrafo->componentes, pVertice);
        LIS_ExcluirElemento(pGrafo->componentes);

        if (LIS_NumeroDeElementos(no->arestas) > 0) {

            vizinhos = (tpAresta**)calloc(LIS_NumeroDeElementos(no->arestas), sizeof(tpAresta*));

            LIS_IrInicioLista(no->arestas);
            do {
                vizinhos[i] = (tpAresta *)LIS_ObterValor(no->arestas);
                i++;
            } while ( LIS_AvancarElementoCorrente(no->arestas,1) == LIS_CondRetOK);
            
            for (i; i; i--) {
                ExcluirAresta(pGrafo, pVertice, vizinhos[i-1]->pVizinho); 
            }
            
            if (pGrafo->ExcluirValor != NULL && no->pValor != NULL) {
                pGrafo->ExcluirValor(no->pValor);
                no->pValor = NULL;
            }
            free(vizinhos);
        }

        LIS_DestruirLista(no->arestas);
        no->arestas = NULL;

        pVertice->pNode = NULL;
        free(no);
        LIS_IrInicioLista(pGrafo->vertices);
        LIS_ProcurarValor(pGrafo->vertices, pVertice);
        LIS_ExcluirElemento(pGrafo->vertices);
        return GRA_CondRetOK;
    }
Exemple #8
0
BAR_tpCondRet BAR_RemoverPeca(BAR_tppCapturadas pBAR)
{
	if(LIS_ExcluirElemento(pBAR->ListaCapturadas) != LIS_CondRetOK)
	{
		printf("Erro ao excluir peca da lsita (BAR) \n");
		return BAR_CondRetErro;
	}
	pBAR->tamanho--;

	return BAR_CondRetOK;
}
Exemple #9
0
/***********************************************************************
*
*  $FC Função: MEN DestruirOpcao
*
***********************************************************************/
    MEN_tpCondRet MEN_DestruirOpcao(MEN_tppMenus m, int idMenu, char cmd){
       MEN_tppMenu menu;
       GRA_ObterValor(m->grafo,idMenu,(void**)&menu); 
       do{
            if(((MEN_tppOpcao)LIS_ObterValor(menu->opcoes))->cmd == cmd){
                LIS_ExcluirElemento(menu->opcoes); 
                return MEN_CondRetOK;
            }
       }
       while(LIS_AvancarElementoCorrente(menu->opcoes,1)==LIS_CondRetOK);
       return MEN_CondRetComandoInvalido;
    }
Exemple #10
0
    static void RemoverAresta(tpVertice* u, tpVertice* v) {
        LIS_tppLista vizinhos = NULL;
        tpAresta * aresta_v = NULL;

        vizinhos = u->pNode->arestas;
        aresta_v = get_edge_by_vertex(vizinhos, v); 

        LIS_IrInicioLista(vizinhos);
        if (aresta_v != NULL && (LIS_ProcurarValor(vizinhos, aresta_v ) == LIS_CondRetOK)) {
            LIS_ExcluirElemento(vizinhos);
        }
    }
Exemple #11
0
    GRA_tpCondRet GRA_InserirAresta( GRA_tppGrafo pGrafo, int idVertice1, int idVertice2 , int idAresta) {
        tpVertice* origem1 = NULL;
        tpVertice* origem2 = NULL;
        tpVertice* pVertice1 = get_by_id(pGrafo,idVertice1);
        tpVertice* pVertice2 = get_by_id(pGrafo,idVertice2);
        tpAresta* vizinho = NULL;   

        /* Verifica se vertice pertence ao grafo; */
        if (pVertice1 == NULL || pVertice2 == NULL) {
            return GRA_CondRetNaoEhVertice;
        }

        if (pVertice1 == pVertice2) {
            return GRA_CondRetEhVizinho;
        }
        if (!EhVizinho(pGrafo, pVertice1, pVertice2)  && 
            !EhVizinho(pGrafo, pVertice2, pVertice1) ) {
            tpAresta * aresta1 = NULL;
            tpAresta * aresta2 = NULL;

            origem1 = ObterOrigem(pGrafo, pVertice1);
            origem2 = ObterOrigem(pGrafo, pVertice2);

            aresta1 = ( tpAresta * ) calloc(1, sizeof( tpAresta )) ;
            if (aresta1 == NULL){
                return GRA_CondRetFaltouMemoria;
            }
            aresta2 = ( tpAresta * ) calloc(1, sizeof( tpAresta )) ;
            if (aresta2 == NULL ) {
                free(aresta1);
                return GRA_CondRetFaltouMemoria;
            }
            aresta1->id = idAresta;
            aresta2->id = idAresta;
            aresta1->pVizinho = pVertice2;
            aresta2->pVizinho = pVertice1;
            LIS_InserirElementoApos(pVertice1->pNode->arestas, aresta1);
            LIS_InserirElementoApos(pVertice2->pNode->arestas, aresta2);     

            if (origem1 != origem2) { //Estavam em componentes distintas? Se sim, junta

                LIS_IrInicioLista(pGrafo->componentes);
                LIS_ProcurarValor(pGrafo->componentes, origem1);
                LIS_ExcluirElemento(pGrafo->componentes);
            }

            return GRA_CondRetOK;
        } 
        else {
            return GRA_CondRetEhVizinho;
        }
    }
Exemple #12
0
    static int BFS(tpVertice* v, tpVertice* u) {
        LIS_tppLista V = NULL; // LISTA VERTICE VISITADOS
        LIS_tppLista Q = NULL; //FILA
        LIS_tppLista arestas = NULL;
        tpVertice* t = NULL;
        tpVertice* s = NULL;
        tpAresta* a = NULL;
        int achou = 0;
        int achou_V = 0;

        V = LIS_CriarLista(NULL); // dados são referenciados por outros, não devem ser apagados
        Q = LIS_CriarLista(NULL); // dados são referenciados por outros, não devem ser apagados

        LIS_InserirElementoApos(V, v);
        LIS_InserirElementoApos(Q, v); //Usado como uma Fila.
        while (LIS_NumeroDeElementos(Q) > 0) {
            LIS_IrInicioLista(Q);
            t = (tpVertice *)LIS_ObterValor(Q);
            LIS_ExcluirElemento(Q);
            if (t == u) {
                achou = 1; 
                break;
            }
            arestas = t->pNode->arestas;
            LIS_IrInicioLista(arestas);
            do {
                a = (tpAresta *)LIS_ObterValor(arestas);
                if(a == NULL) continue;
                s = a->pVizinho;
                
                LIS_IrInicioLista(V);
                achou_V = 0;
                do {
                    tpVertice * re = (tpVertice *)LIS_ObterValor(V);
                    if (re == NULL) {
                        continue;
                    }
                    if(re == s) achou_V = 1;
                } while(LIS_AvancarElementoCorrente(V, 1) == LIS_CondRetOK);
            
                if (!achou_V) {
                    if(LIS_InserirElementoApos(V, s)!= LIS_CondRetOK){ achou = -1;break;}
                    if(LIS_InserirElementoApos(Q, s)!= LIS_CondRetOK){ achou = -1;break;}
                }
            } while(LIS_AvancarElementoCorrente(arestas, 1) == LIS_CondRetOK);
        }

        LIS_DestruirLista(V);
        LIS_DestruirLista(Q);

        return achou;
    }
Exemple #13
0
void DestruirMatriz ( LIS_tppLista Tab ) {
	
	LIS_tppLista Col;
	PtoTopo* p;

	while ( Tab != NULL) {
			
			IrFinalLista( Tab );
			Col = (LIS_tppLista) LIS_ObterValor( Tab );
			
		while (Col != NULL) {
				IrFinalLista( Col );
				p = (PtoTopo*) LIS_ObterValor( Col );
				libera( p );
				LIS_ExcluirElemento( Col );
				IrInicioLista( Col );			
		}

			LIS_ExcluirElemento( Tab );
			IrInicioLista( Tab );
	}		

		free ( Tab );
}
Exemple #14
0
enum GRA_Ret GRA_RemLink (Graph *g, void *d)
{
	Node *curr;
	Link *l;
    CNT_CONTAR("GRA_RemLink - Inicio");
	if (!d){
        CNT_CONTAR("GRA_RemLink - Nao existe d");
		return GRA_NullData;
    }
	if (!g->currentNode){
        CNT_CONTAR("GRA_RemLink - Nao existe g->currentNode");
		return GRA_InvalidCurrentNode;
    }
#ifdef _DEBUG
	AssertGraph(g);
#endif /* _DEBUG */
	curr = LIS_ObterValor (g->currentNode);
#ifdef _DEBUG
	AssertNode(curr,g);
#endif /* _DEBUG */

    CNT_CONTAR("GRA_RemLink - Procurando elemento");
	IrInicioLista (curr->links);
	do{
        CNT_CONTAR("GRA_RemLink - Avanando na lista");
		l = (Link*)LIS_ObterValor (curr->links);
		#ifdef _DEBUG
		AssertLink(l);
		#endif /* _DEBUG */
		if (l->n2->data == d){
             CNT_CONTAR("GRA_RemLink - Deletando elemento");
			/* deleta de curr -> n2 */
			LIS_ExcluirElemento(curr->links);
				/* isso deleta link e link->brother */
			#ifdef _DEBUG
			g->nOfLinks -= 2 ;
			AssertGraph(g);
			#endif /* _DEBUG */
			return GRA_Ok;
		}
	}while (LIS_AvancarElementoCorrente(curr->links, 1)
			== LIS_CondRetOK);

    CNT_CONTAR("GRA_RemLink - Finalizando");
	return GRA_InvalidArgNode;
}
Exemple #15
0
void delLink (Link *l)
{
	static int RecursionCnt = 0;

	RecursionCnt++;
	IrInicioLista( l->n2->links );

	CNT_CONTAR("delLink - Inicio");
	if ( RecursionCnt <= 1 &&
			LIS_CondRetOK == LIS_ProcurarValor(l->n2->links,l->brother) ){
			CNT_CONTAR("delLink - Achou: Deletando Lista de Links");
		LIS_ExcluirElemento(l->n2->links);
	}
	CNT_CONTAR("delLink - Finalizando");
	free (l);
	RecursionCnt--;
}
/***************************************************************************
*
*  Função: PIL  &Remover Carta
*  ****/
PIL_tpCondRet PIL_RemoverCarta( PIL_tpPilha pPilha , CAR_tpCarta * pCarta ) {

	LIS_tpCondRet condRetLis;
	CAR_tpCarta carta;

	if (pPilha == NULL)
		return PIL_CondRetPilhaNaoExiste;

	condRetLis = LIS_ObterValor( pPilha->cabeca , (void**)&carta);

	if (condRetLis != LIS_CondRetOK)
		return PIL_CondRetPilhaVazia; 
	else {
		CAR_tpCarta cartaCriada;
		CAR_tpValor valor;
		CAR_tpNaipe naipe;
		CAR_tpEstado estado;
		CAR_tpCondRet condRetCar;

		//nao precisa testar cond de ret porque já foi garantido que carta existe
		CAR_ObterValor(carta,&valor);
		
		CAR_ObterNaipe(carta,&naipe);
	
		CAR_ObterEstado(carta,&estado);

		condRetCar = CAR_CriarCarta( &cartaCriada,valor,naipe);

		if (estado == CAR_EstadoInvisivel)
			CAR_TornarInvisivel(cartaCriada);

		if (condRetCar == CAR_CondRetFaltouMemoria)
			return PIL_CondRetFaltouMemoria;
		else {
			 LIS_ExcluirElemento( pPilha->cabeca );
			 *pCarta = cartaCriada;
			//aqui há garantia que a lista nao esta vazia pois ja se obteve o valor anteriormente
			return PIL_CondRetOK;
		}

	}
}
Exemple #17
0
/***********************************************************************
*
*  $FC Função: PILHA Pop Pilha
*
*  $FV Valor retornado
*	  PILHA_CondRetNaoExiste Caso a PILHA nao exista
*	  PILHA_CondRetOk
*		$ED Descrição do tipo
*		tira um elemento do topo da pilha
***********************************************************************/
PILHA_tpCondRet PILHA_Pop(PILHA_tppPilha p, CRT_tppCarta * carta){
	int crt[2];
	int condRet = 0;
	CRT_tppCarta crt_aux = NULL;

	if (p == NULL){
#ifdef _DEBUG
		CNT_CONTAR("PILHA_Pop-PilhaInexistente");
#endif
		return PILHA_CondRetPilhaInexistente;
	}
	if (p->topo == NULL){
#ifdef _DEBUG
		CNT_CONTAR("PILHA_Pop-PilhaTopoInexistente");
#endif
		return PILHA_CondRetPilhaInexistente;
	}
	//LIS_AvancarElementoCorrente(p->topo);
	crt_aux = (CRT_tppCarta)LIS_ObterValor(p->topo);
	CRT_ObtemCarta(crt_aux, &crt[0], &crt[1]);

	condRet = LIS_ExcluirElemento(p->topo);

	if (condRet == 1){
#ifdef _DEBUG
		CNT_CONTAR("PILHA_Pop-PilhaTopoInexistente-2");
#endif
		p = NULL;
		return PILHA_CondRetPilhaInexistente;
	}

	CRT_CriaCarta(&crt_aux, crt[0], crt[1]);
	*carta = crt_aux;
	p->quantidade -= 1;

	return PILHA_CondRetOK;

} /* Fim função: PILHA POP Pilha */
/***************************************************************************
*  Função: GRA Deixar de ser origem
******/
GRA_tpCondRet GRA_DeixarDeSerOrigem(GRA_tppGrafo pGrafoParm)
{
   tpGrafo *pGrafo = (tpGrafo*) pGrafoParm;

   if (pGrafo == NULL)
   {
      return GRA_CondRetGrafoNaoFoiCriado;
   }

   if (EstaVazio(pGrafo))
   {
      return GRA_CondRetGrafoVazio;
   }

   if (!ExisteOrigem(pGrafo, pGrafo->pCorrente->nome))
   {
      return GRA_CondRetNaoAchou;
   }

   LIS_ExcluirElemento(pGrafo->pOrigens);

   return GRA_CondRetOK;
}
Crt * PDCRT_Pop( LIS_tppCabeca * cb )
{
	Crt * carta , * temp;

	char * valor  ;
	char naipe ;
	int estado ;
	int situacao ;

	LIS_IrInicioLista( cb ) ;

	temp = ( Crt * ) LIS_ObterValor( cb ) ;
	valor = CTA_AcessaValor( temp ) ;
	naipe = CTA_AcessaNaipe( temp ) ;
	estado = CTA_AcessaEstado( temp ) ;
	situacao = CTA_AcessaSituacao( temp ) ;

	carta = CTA_CriaCarta ( valor , naipe , estado , situacao ) ;

	LIS_ExcluirElemento( cb ) ;

	return carta ;
} /* Fim função: PDCRT Pop */
Exemple #20
0
void GRA_ExcluirdeVertices(GRA_tppGrafo pGrafo , tpVerticeGrafo * pVertice)
{

	tpVerticeGrafo * pVert;

	ListaRet = LIS_IrInicioLista(pGrafo->pListaVertices);

	while(ListaRet == LIS_CondRetOK || ListaRet == LIS_CondRetFimLista)
	{

		LIS_ObterValor(pGrafo->pListaVertices , (void**)&pVert);
		if(pVertice->pIdVertice == pVert->pIdVertice){
			LIS_ExcluirElemento (pGrafo->pListaVertices);
		}
		if(ListaRet == LIS_CondRetFimLista){
			break;
		}
		ListaRet = LIS_AvancarElementoCorrente(pGrafo->pListaVertices, 1);

	}
	

} /* Fim função: GRA &Limpa o conteúdo da lista de vértices do grafo  */
/***************************************************************************
*  Função: GRA Destruir vértice corrente
******/
GRA_tpCondRet GRA_DestruirVerticeCorrente(GRA_tppGrafo pGrafoParm)
{
	tpGrafo *pGrafo = NULL;
	tpVertice  *pVerticeOrigem = NULL, *pVertice = NULL;
	tpAresta *pAresta = NULL;
	int estaVazia = -1, numElemLista = 0;

	if (pGrafoParm == NULL)
	{
		return GRA_CondRetGrafoNaoFoiCriado;
	}

	pGrafo = (tpGrafo*) pGrafoParm;

	if (EstaVazio(pGrafo))
	{
		return GRA_CondRetGrafoVazio;
	}

	LIS_EstaVazia(pGrafo->pOrigens,&estaVazia);

	if (estaVazia)
	{
		return GRA_CondRetNaoAchou;
	}

	// remove corrente vai para origem
	// Navega para o inicio da lista de origens
	LIS_IrInicioLista(pGrafo->pOrigens);
	//Pega o valor do primeiro vértice de origem
	LIS_ObterValor(pGrafo->pOrigens,(void**)&pVerticeOrigem);

	//remove arestas do vertice corrente
	LIS_EsvaziarLista(pGrafo->pCorrente->pSucessores);

	// Para cada item da lista de anteressores, remover aresta que aponta para o corrente
	LIS_NumELementos(pGrafo->pCorrente->pAntecessores,&numElemLista);
	LIS_IrInicioLista(pGrafo->pCorrente->pAntecessores);

	while(numElemLista > 0)
	{
		int nElem = 0;
		LIS_ObterValor(pGrafo->pCorrente->pAntecessores,(void**)&pVertice);

		LIS_NumELementos(pVertice->pSucessores, &nElem);
		LIS_IrInicioLista(pVertice->pSucessores);

		while(nElem > 0)
		{
			LIS_ObterValor(pVertice->pSucessores,(void**)&pAresta);

			if(!strcmp(pAresta->pVertice->nome, pGrafo->pCorrente->nome))
			{
				LIS_ExcluirElemento(pVertice->pSucessores);
				break;
			}

			LIS_AvancarElementoCorrente(pVertice->pSucessores,1);
			nElem--;
		}
		LIS_AvancarElementoCorrente(pGrafo->pCorrente->pAntecessores,1);
		numElemLista--;
	}

	//Exclui elemento corrente
	LIS_IrInicioLista(pGrafo->pVertices);
	LIS_ProcurarValor(pGrafo->pVertices,pGrafo->pCorrente->nome);
	LIS_ExcluirElemento(pGrafo->pVertices);

	pGrafo->pCorrente = pVerticeOrigem;
	

	return GRA_CondRetOK;
}
Exemple #22
0
TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
{

    int inxLista  = -1 ,
        numLidos   = -1 ,
        CondRetEsp = -1  ;

    char   StringDado[  DIM_VALOR ] ;

    int ValEsp = -1 ;

    int i ;

    int numElem = -1 ;

    StringDado[ 0 ] = 0 ;

    /* Efetuar reset de teste de lista */

    if ( strcmp( ComandoTeste , RESET_LISTA_CMD ) == 0 )
    {

        for( i = 0 ; i < DIM_VT_LISTA ; i++ )
        {
            vtListas[ i ] = NULL ;
        } /* for */

        return TST_CondRetOK ;

    } /* fim ativa: Efetuar reset de teste de lista */

    /* Testar CriarLista */

    else if ( strcmp( ComandoTeste , CRIAR_LISTA_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "i" ,
                                      &inxLista ) ;

        if ( ( numLidos != 1 )
                || ( ! ValidarInxLista( inxLista , VAZIO )))
        {
            return TST_CondRetParm ;
        } /* if */

        vtListas[ inxLista ] =
            LIS_CriarLista( DestruirValor ) ;

        return TST_CompararPonteiroNulo( 1 , vtListas[ inxLista ] ,
                                         "Erro em ponteiro de nova lista."  ) ;

    } /* fim ativa: Testar CriarLista */

    /* Testar Esvaziar lista lista */

    else if ( strcmp( ComandoTeste , ESVAZIAR_LISTA_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "i" ,
                                      &inxLista ) ;

        if ( ( numLidos != 1 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
        {
            return TST_CondRetParm ;
        } /* if */

        LIS_EsvaziarLista( vtListas[ inxLista ] ) ;

        return TST_CondRetOK ;

    } /* fim ativa: Testar Esvaziar lista lista */

    /* Testar Destruir lista */

    else if ( strcmp( ComandoTeste , DESTRUIR_LISTA_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "i" ,
                                      &inxLista ) ;

        if ( ( numLidos != 1 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
        {
            return TST_CondRetParm ;
        } /* if */

        LIS_DestruirLista( vtListas[ inxLista ] ) ;
        vtListas[ inxLista ] = NULL ;

        return TST_CondRetOK ;

    } /* fim ativa: Testar Destruir lista */

    /* Testar inserir elemento antes */

    else if ( strcmp( ComandoTeste , INS_ELEM_ANTES_CMD ) == 0 )
    {
        struct user *u = (struct user*) malloc (sizeof (struct user));
        LIS_tpCondRet lret;
        if (!u)
            return TST_CondRetMemoria;

        numLidos = LER_LerParametros( "isssi" ,
                                      &inxLista , u->nome, u->tel, u->ender , &CondRetEsp ) ;

        if ( ( numLidos != 5 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        lret = LIS_InserirElementoAntes( vtListas[ inxLista ] , u ) ;

        if ( lret != LIS_CondRetOK )
        {
            free( u ) ;
        } /* if */

        return TST_CompararInt( CondRetEsp , lret ,
                                "Condicao de retorno errada ao inserir antes."                   ) ;

    } /* fim ativa: Testar inserir elemento antes */

    /* Testar inserir elemento apos */

    else if ( strcmp( ComandoTeste , INS_ELEM_APOS_CMD ) == 0 )
    {
        struct user *u = (struct user *)malloc (sizeof (struct user));
        LIS_tpCondRet lret;
        if (!u)
            return TST_CondRetMemoria;

        numLidos = LER_LerParametros( "isssi",
                                      &inxLista, u->nome, u->tel, u->ender, &CondRetEsp ) ;

        if ( ( numLidos != 5 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        lret = LIS_InserirElementoApos( vtListas[ inxLista ] , u ) ;

        if ( lret != LIS_CondRetOK )
        {
            free( u ) ;
        } /* if */

        return TST_CompararInt( CondRetEsp , lret,
                                "Condicao de retorno errada ao inserir antes.") ;
    } /* fim ativa: Testar inserir elemento apos */

    /* Testar excluir simbolo */

    else if ( strcmp( ComandoTeste , EXC_ELEM_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "ii" ,
                                      &inxLista , &CondRetEsp ) ;

        if ( ( numLidos != 2 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        return TST_CompararInt( CondRetEsp ,
                                LIS_ExcluirElemento( vtListas[ inxLista ] ) ,
                                "Condição de retorno errada ao excluir."   ) ;

    } /* fim ativa: Testar excluir simbolo */

    /* Testar obter valor do elemento corrente */
    else if ( strcmp( ComandoTeste , OBTER_NOME_CMD ) == 0 )
    {
        struct user *u;
        numLidos = LER_LerParametros( "isi" ,
                                      &inxLista , StringDado , &ValEsp ) ;

        if ( ( numLidos != 3 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        u = (struct user*) LIS_ObterValor( vtListas[ inxLista ] ) ;

        if ( ValEsp == 0 )
        {
            return TST_CompararPonteiroNulo( 0 , u,
                                             "Valor não deveria existir." ) ;
        } /* if */

        if ( u == NULL )
        {
            return TST_CompararPonteiroNulo( 1 , u,
                                             "Dado tipo um deveria existir." ) ;
        } /* if */

        return TST_CompararString( StringDado , u->nome,
                                   "Valor nome do elemento esta' errado." ) ;
    } /* fim ativa: Testar obter valor do elemento corrente */

    /* Testar obter valor do elemento corrente */
    else if ( strcmp( ComandoTeste, OBTER_TEL_CMD ) == 0 )
    {
        struct user *u;
        numLidos = LER_LerParametros( "isi" ,
                                      &inxLista , StringDado , &ValEsp ) ;

        if ( ( numLidos != 3 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        u = (struct user*) LIS_ObterValor( vtListas[ inxLista ] ) ;

        if ( ValEsp == 0 )
        {
            return TST_CompararPonteiroNulo( 0 , u,
                                             "Valor não deveria existir." ) ;
        } /* if */

        if ( u == NULL )
        {
            return TST_CompararPonteiroNulo( 1 , u,
                                             "Dado tipo um deveria existir." ) ;
        } /* if */

        return TST_CompararString( StringDado , u->tel,
                                   "Valor nome do elemento esta' errado." ) ;
    } /* fim ativa: Testar obter valor do elemento corrente */
    /* Testar obter valor do elemento corrente */
    else if ( strcmp( ComandoTeste , OBTER_ENDER_CMD ) == 0 )
    {
        struct user *u;
        numLidos = LER_LerParametros( "isi" ,
                                      &inxLista , StringDado , &ValEsp ) ;

        if ( ( numLidos != 3 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        u = (struct user*) LIS_ObterValor( vtListas[ inxLista ] ) ;

        if ( ValEsp == 0 )
        {
            return TST_CompararPonteiroNulo( 0 , u,
                                             "Valor não deveria existir." ) ;
        } /* if */

        if ( u == NULL )
        {
            return TST_CompararPonteiroNulo( 1 , u,
                                             "Dado tipo um deveria existir." ) ;
        } /* if */

        return TST_CompararString( StringDado , u->ender,
                                   "Valor nome do elemento esta' errado." ) ;
    } /* fim ativa: Testar obter valor do elemento corrente */

    /* Testar ir para o elemento inicial */

    else if ( strcmp( ComandoTeste , IR_INICIO_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "i" , &inxLista ) ;

        if ( ( numLidos != 1 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        IrInicioLista( vtListas[ inxLista ] ) ;

        return TST_CondRetOK ;

    } /* fim ativa: Testar ir para o elemento inicial */

    /* LIS  &Ir para o elemento final */

    else if ( strcmp( ComandoTeste , IR_FIM_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "i" , &inxLista ) ;

        if ( ( numLidos != 1 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        IrFinalLista( vtListas[ inxLista ] ) ;

        return TST_CondRetOK ;

    } /* fim ativa: LIS  &Ir para o elemento final */

    /* LIS  &Avançar elemento */

    else if ( strcmp( ComandoTeste , AVANCAR_ELEM_CMD ) == 0 )
    {

        numLidos = LER_LerParametros( "iii" , &inxLista , &numElem ,
                                      &CondRetEsp ) ;

        if ( ( numLidos != 3 )
                || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
        {
            return TST_CondRetParm ;
        } /* if */

        return TST_CompararInt( CondRetEsp ,
                                LIS_AvancarElementoCorrente( vtListas[ inxLista ] , numElem ) ,
                                "Condicao de retorno errada ao avancar" ) ;

    } /* fim ativa: LIS  &Avançar elemento */

    return TST_CondRetNaoConhec ;

} /* Fim função: TLIS &Testar lista */
Exemple #23
0
TST_tpCondRet TST_EfetuarComando(char * ComandoTeste)
{
    int inxLista  = -1, numLidos   = -1, CondRetEsp = -1;

    TST_tpCondRet CondRet;

    char   StringDado[DIM_VALOR];
    char * pDado;

    int IntDado[DIM_VALOR_INT];
    int* pDadoInt;

    int ValEsp = -1;
    int i;
    int numElem = -1;

    int inxStoredPtr;

    for(i = 0; i < DIM_VT_LISTA; i++)
        storedPtr[i][0] = NULL;
    StringDado[0] = 0;

    /* Efetuar reset de teste de lista */
    if(strcmp(ComandoTeste, RESET_LISTA_CMD) == 0) {
        for(i = 0; i < DIM_VT_LISTA; i++) {
            vtListas[i] = NULL;
            storedPtrIndex[i] = 1;
        }

        return TST_CondRetOK;

    } /* fim ativa: Efetuar reset de teste de lista */

    /* Testar CriarLista */
    else if(strcmp(ComandoTeste, CRIAR_LISTA_CMD) == 0) {
        numLidos = LER_LerParametros("i", &inxLista);

        if((numLidos != 1) || (!ValidarInxLista(inxLista, VAZIO)))
            return TST_CondRetParm;

        vtListas[inxLista] = LIS_CriarLista(DestruirValor);

        return TST_CompararPonteiroNulo(1, vtListas[inxLista], "Erro em ponteiro de nova lista.");
    } /* fim ativa: Testar CriarLista */

    /* Testar Esvaziar lista lista */
    else if(strcmp(ComandoTeste, ESVAZIAR_LISTA_CMD) == 0) {
        numLidos = LER_LerParametros("i", &inxLista);

        if((numLidos != 1) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        LIS_EsvaziarLista(vtListas[inxLista]);
        return TST_CondRetOK;

    } /* fim ativa: Testar Esvaziar lista lista */

    /* Testar Destruir lista */
    else if(strcmp(ComandoTeste, DESTRUIR_LISTA_CMD) == 0) {
        numLidos = LER_LerParametros("i", &inxLista);

        if((numLidos != 1) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        LIS_DestruirLista(vtListas[inxLista]);
        vtListas[inxLista] = NULL;
        return TST_CondRetOK;

    } /* fim ativa: Testar Destruir lista */

    /* Testar inserir elemento antes */
    else if(strcmp(ComandoTeste, INS_ELEM_ANTES_CMD) == 0) {
        numLidos = LER_LerParametros("isi", &inxLista, StringDado, &CondRetEsp);

        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(storedPtrIndex[inxLista]))
            return TST_CondRetMemoria;

        pDado = (char *) malloc(strlen(StringDado) + 1);
        if(pDado == NULL)
            return TST_CondRetMemoria;

        storedPtr[inxLista][storedPtrIndex[inxLista]++] = pDado;
        strcpy(pDado, StringDado);

        CondRet = LIS_InserirElementoAntes(vtListas[inxLista], pDado);
        if(CondRet != LIS_CondRetOK)
            free(pDado);

        return TST_CompararInt(CondRetEsp, CondRet, "Condicao de retorno errada ao inserir antes.");
    } /* fim ativa: Testar inserir elemento antes */

    /* Testar inserir elemento antes INTEIRO */
    else if(strcmp(ComandoTeste, INS_ELEM_ANTES_CMD_INT) == 0) {
        numLidos = LER_LerParametros("iiii", &inxLista, &IntDado[0], &IntDado[1], &CondRetEsp);

        if((numLidos != 4) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(storedPtrIndex[inxLista]))
            return TST_CondRetMemoria;

        pDadoInt = (int *) malloc(DIM_VALOR_INT*sizeof(int));
        if(pDadoInt == NULL)
            return TST_CondRetMemoria;

        storedPtr[inxLista][storedPtrIndex[inxLista]++] = pDadoInt;
        for(i=0;i<DIM_VALOR_INT;i++)
            pDadoInt[i]=IntDado[i];

        CondRet = LIS_InserirElementoAntes(vtListas[inxLista], pDadoInt);
        if(CondRet != LIS_CondRetOK)
            free(pDadoInt);

        return TST_CompararInt(CondRetEsp, CondRet, "Condicao de retorno errada ao inserir antes.");
    } /* fim ativa: Testar inserir elemento antes INTEIRO*/

    /* Testar inserir elemento apos */
    else if(strcmp(ComandoTeste, INS_ELEM_APOS_CMD) == 0) {
        numLidos = LER_LerParametros("isi", &inxLista, StringDado, &CondRetEsp);

        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(storedPtrIndex[inxLista]))
            return TST_CondRetMemoria;

        pDado = (char*)malloc(strlen(StringDado) + 1);
        if(pDado == NULL)
            return TST_CondRetMemoria;

        storedPtr[inxLista][storedPtrIndex[inxLista]++] = pDado;
        strcpy(pDado, StringDado);

        CondRet = LIS_InserirElementoApos(vtListas[inxLista], pDado);
        if(CondRet != LIS_CondRetOK)
            free(pDado);

        return TST_CompararInt(CondRetEsp, CondRet, "Condicao de retorno errada ao inserir apos.");
    } /* fim ativa: Testar inserir elemento apos */

    /* Testar inserir elemento apos INTEIRO*/
    else if(strcmp(ComandoTeste, INS_ELEM_APOS_CMD_INT) == 0) {
        numLidos = LER_LerParametros("iiii", &inxLista, &IntDado[0], &IntDado[1], &CondRetEsp);

        if((numLidos != 4) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(storedPtrIndex[inxLista]))
            return TST_CondRetMemoria;

        pDadoInt = (int *) malloc(DIM_VALOR_INT * sizeof(int));
        if(pDadoInt == NULL)
            return TST_CondRetMemoria;

        storedPtr[inxLista][storedPtrIndex[inxLista]++] = pDadoInt;
        for(i=0;i<DIM_VALOR_INT;i++)
            pDadoInt[i]=IntDado[i];

        CondRet = LIS_InserirElementoApos(vtListas[inxLista], pDadoInt);

        if(CondRet != LIS_CondRetOK)
            free(pDadoInt);

        return TST_CompararInt(CondRetEsp, CondRet, "Condicao de retorno errada ao inserir apos.");
    } /* fim ativa: Testar inserir elemento apos INTEIRO*/

    /* Testar excluir simbolo */
    else if(strcmp(ComandoTeste, EXC_ELEM_CMD) == 0) {
        numLidos = LER_LerParametros("ii", &inxLista, &CondRetEsp);

        if((numLidos != 2) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        return TST_CompararInt(CondRetEsp, LIS_ExcluirElemento(vtListas[inxLista]),
                               "Condição de retorno errada ao excluir.");
    } /* fim ativa: Testar excluir simbolo */

    /* Testar obter valor do elemento corrente */
    else if(strcmp(ComandoTeste, OBTER_VALOR_CMD) == 0) {
        numLidos = LER_LerParametros("isi", &inxLista, StringDado, &ValEsp);

        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        pDado = (char *) LIS_ObterValor(vtListas[inxLista]);
        if(ValEsp == 0)
            return TST_CompararPonteiroNulo(0, pDado, "Valor não deveria existir.");

        if(pDado == NULL)
            return TST_CompararPonteiroNulo(1, pDado, "Dado tipo um deveria existir.");

        return TST_CompararString(StringDado, pDado, "Valor do elemento errado.");
    } /* fim ativa: Testar obter valor do elemento corrente */

    /* Testar obter valor do elemento corrente INTEIRO*/
    else if(strcmp(ComandoTeste, OBTER_VALOR_CMD_INT) == 0) {
        numLidos = LER_LerParametros("iiii", &inxLista, &IntDado[0], &IntDado[1], &ValEsp);

        if((numLidos != 4) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        pDadoInt = (int *)LIS_ObterValor(vtListas[inxLista]);
        if(ValEsp == 0)
            return TST_CompararPonteiroNulo(0, pDadoInt, "Valor não deveria existir.");

        if(pDadoInt == NULL)
            return TST_CompararPonteiroNulo(1, pDadoInt, "Dado tipo um deveria existir.");

        return TST_CompararEspaco(IntDado, pDadoInt, DIM_VALOR_INT * sizeof(int),
                                  "Valor do elemento errado.");
    } /* fim ativa: Testar obter valor do elemento corrente INTEIRO*/

    /* Testar ir para o elemento inicial */
    else if(strcmp(ComandoTeste, IR_INICIO_CMD) == 0) {
        numLidos = LER_LerParametros("i", &inxLista);

        if((numLidos != 1) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        LIS_IrInicioLista(vtListas[inxLista]);
        return TST_CondRetOK;
    } /* fim ativa: Testar ir para o elemento inicial */

    /* LIS  &Ir para o elemento final */
    else if(strcmp(ComandoTeste, IR_FIM_CMD) == 0) {
        numLidos = LER_LerParametros("i", &inxLista);

        if((numLidos != 1) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        LIS_IrFinalLista(vtListas[inxLista]);
        return TST_CondRetOK;
    } /* fim ativa: LIS  &Ir para o elemento final */

    /* LIS  &Avançar elemento */
    else if(strcmp(ComandoTeste, AVANCAR_ELEM_CMD) == 0) {
        numLidos = LER_LerParametros("iii", &inxLista, &numElem, &CondRetEsp);

        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        return TST_CompararInt(CondRetEsp,
                               LIS_AvancarElementoCorrente(vtListas[inxLista], numElem),
                               "Condicao de retorno errada ao avancar");

    } /* fim ativa: LIS  &Avançar elemento */

    /* Testar Ir Indice */
    else if(strcmp(ComandoTeste, IR_INDICE_CMD) == 0) {
        numLidos = LER_LerParametros("iii", &inxLista, &numElem, &CondRetEsp);
        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        return TST_CompararInt(CondRetEsp, LIS_IrIndice(vtListas[inxLista], numElem),
                               "Condicao de retorno errada ao ir para o índice");
    } /* fim ativa: Testar Ir Indice */

    /* Testar Setar Valor INTEIRO*/
    else if(strcmp(ComandoTeste, SETAR_VALOR_CMD_INT) == 0) {
        numLidos = LER_LerParametros("iiii", &inxLista, &IntDado[0], &IntDado[1], &CondRetEsp);
        if((numLidos != 4) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(storedPtrIndex[inxLista]))
            return TST_CondRetMemoria;

        pDadoInt = (int *) malloc(DIM_VALOR_INT * sizeof(int));
        if(pDadoInt == NULL)
            return TST_CondRetMemoria;

        storedPtr[inxLista][storedPtrIndex[inxLista]++] = pDadoInt;
        for(i=0;i<DIM_VALOR_INT;i++)
            pDadoInt[i]=IntDado[i];

        return TST_CompararInt(CondRetEsp, LIS_SetarValor(vtListas[inxLista], pDadoInt),
                               "Condicao de retorno errada ao ir marcar o valor");
    } /* fim ativa: LIS  Setar Valor INTEIRO*/

    /* Testar Procurar Valor */
    else if(strcmp(ComandoTeste, PROCURAR_VALOR_CMD) == 0) {
        numLidos = LER_LerParametros("iii", &inxLista, &inxStoredPtr, &CondRetEsp);
        if((numLidos != 3) || (!ValidarInxLista(inxLista, NAO_VAZIO)))
            return TST_CondRetParm;

        if(!ValidarInxStoredPtr(inxStoredPtr))
            return TST_CondRetParm;

        return TST_CompararInt(CondRetEsp, LIS_ProcurarValor(vtListas[inxLista], storedPtr[inxLista][inxStoredPtr]),
                               "Condicao de retorno errada ao procurar valor");
    } /* fim ativa: LIS Procurar Valor */

    return TST_CondRetNaoConhec;
} /* Fim função: TLIS &Testar lista */
Exemple #24
0
    GRA_tpCondRet GRA_BuscarCaminho( GRA_tppGrafo pGrafo , int idVerticeOrigem, int idVerticeDestino, LIS_tppLista * pLista ) {
        tpVertice * v = NULL;
        tpVertice * u = NULL;         
        tpVertice * origem1 = NULL;
        tpVertice * origem2 = NULL;
        int lenV = 0;
        LIS_tppLista Q = NULL; //FILA
        LIS_tppLista arestas = NULL;
        LIS_tppLista retorno = NULL;
        int t;
        int len = 0;
        int achou = 0;
        int ok = 0;
        int i,j,in;
        int lenD;
        int alt = 0;
        int* visitados = NULL; // Vetor de vertices visitados
        int* vizinhos = NULL;
        int* idAux = NULL;
        Dist** dists = NULL;
        Dist* dist = NULL; //aux;
        Dist* currDist = NULL;

        lenD = 1;

        v = get_by_id(pGrafo, idVerticeOrigem);
        u = get_by_id(pGrafo, idVerticeDestino);
        if(v == NULL || u == NULL) {
            return GRA_CondRetNaoEhVertice; 
        }

        origem1 = ObterOrigem(pGrafo, v);
        origem2 = ObterOrigem(pGrafo, u);
        if (origem1 != origem2) {
            return GRA_CondRetNaoEhConexo;
        }//Else: É conexo, devia retornar Ok.
        

        for (;;) {
            dists = (Dist**)calloc(LIS_NumeroDeElementos(pGrafo->vertices)+1, sizeof(Dist*));
            if (dists == NULL) {break;}
            dists[0] = newDist(idVerticeOrigem, 0);

            retorno = LIS_CriarLista(free);
            if (retorno == NULL) { break; }
            else if (v == u) {
                if( LIS_InserirElementoApos(retorno, newInt(idVerticeOrigem)) == LIS_CondRetOK) {
                    *pLista = retorno;
                    return GRA_CondRetOK;
                } else {
                    break;
                }
            }

            visitados = (int*) calloc(LIS_NumeroDeElementos(pGrafo->vertices)+1,sizeof(int));
            if (visitados == NULL) { break; }

            Q = LIS_CriarLista(free);
            if (Q == NULL) { break; }

            visitados[0] = idVerticeOrigem;
            lenV = 1;
            if (LIS_InserirElementoApos(Q, newInt(idVerticeOrigem)) != LIS_CondRetOK) { break;} //enque

            ok = 1;
            break;
        }
        if (!ok) {
            free(dists);
            LIS_DestruirLista(retorno);
            free(visitados);
            LIS_DestruirLista(Q);
            return GRA_CondRetFaltouMemoria;
        }

        while (LIS_NumeroDeElementos(Q) > 0) {
            //dequeue
            LIS_IrInicioLista(Q);
            t = getInt(LIS_ObterValor(Q));
            LIS_ExcluirElemento(Q);

            //Iterar sobre vizinhos
            GRA_ObterVizinhos(pGrafo, t, &arestas);
            vizinhos = converteListaParaVetorDeInteiros(arestas, &len);
            LIS_DestruirLista(arestas);
            arestas = NULL;

            currDist = getDist(dists, t);
            if(!currDist) {
                return GRA_CondRetFaltouMemoria;
            } else {
            }
            alt = currDist->dist + 1;
            for (i=0; i < len; i++) {
                
                in = 0;
                for (j=0; j < lenV; j++) {
                    if (visitados[j] == vizinhos[i]) {
                        in = 1;
                    }
                }
                if (!in) {
                    dist = getDist(dists, vizinhos[i]);
                    if (dist == NULL) { //infinity
                        dists[lenD] = newDist(vizinhos[i], alt);
                        dists[lenD]->prev = currDist;
                        dist = dists[lenD];
                        lenD++;
                    } else if (alt < dist->dist) {
                        dist->dist = alt;
                        dist->prev = currDist;
                    }
                    if (idVerticeDestino == vizinhos[i]) {
                        currDist = dist;
                        achou = 1;
                    }
                    visitados[lenV] = vizinhos[i];
                    lenV++;
                    LIS_InserirElementoAntes(Q, newInt(vizinhos[i]));
                }
            }
            free(vizinhos);
            if (achou) {
                currDist = dist;
                break;
            }
            if(lenV == LIS_NumeroDeElementos(pGrafo->vertices)) {
                break;
            }
        }
        
        if (achou) {
            //printf("\n");
            // for(i=0; i < lenD; i++) {
            //     printf("endr: %p, id: %d, dist: %d, prev: %p \n", *(dists+i), dists[i]->id, dists[i]->dist, dists[i]->prev);
            // }
            while (currDist) {
                LIS_InserirElementoAntes(retorno, newInt(currDist->id));
                currDist  = currDist->prev;
            }

        }

        

        


        //Limpando a memória        
        for (i=0; i < lenD; i++) {
            free(dists[i]);
        }
        free(dists);
        free(visitados);
        LIS_DestruirLista(Q);
        *pLista = retorno;
        return GRA_CondRetOK;
    }
int main (void)
{
	int qtdprocessos, met;
	FILE* out = fopen("saida.txt","w");
	int i, j, fail = 0, cnt = 0, tamProntos, tamIO, tamIO2, seg = 0, inxExec, inxIO;
	Processo *aux, *procExec, *procIO, *procRetirado;
	LIS_tppLista listaIO = LIS_CriarLista();
	LIS_tppLista listaProntos = LIS_CriarLista();
	Memory *	mem = (Memory*)malloc(sizeof(Memory));
	FILE* fp = fopen("entrada.txt", "r");
	Processo *vp = (Processo*)malloc(100*sizeof(Processo));
	qtdprocessos = lerEntrada(&fp, vp);
	imprimeVetor(vp, qtdprocessos);
	InicializaMemoria(mem);
	procExec = NULL;
	// Insere os elementos lidos numa lista de prontos
	for(i = 0; i < qtdprocessos; i++)
	{
		LIS_InserirElementoApos(listaProntos, &vp[i]);
		LIS_AvancarElementoCorrente(listaProntos, 1);
		vp[i].segAtual = -1;
		vp[i].naMemoria = 0;
		vp[i].t_exec = 0;
		vp[i].t_io = 0;
	}
	printf("1: First Fit \n");
	printf("2: Best Fit \n");
	printf("3: Worst Fit \n");
	printf("4: Next Fit \n");
	scanf("%d", &met);
EXEC:
	IrInicioLista(listaProntos); // vai pro inicio da lista de prontos
	aux = (Processo*)LIS_ObterValor(listaProntos);
	switch(met)
	{
	case 1:
		firstFit(mem, listaProntos);
		break;
	case 2:
		BestFit(mem, listaProntos);
		break;
	case 3:
		WorstFit(mem, listaProntos);
		break;
	case 4:
		NextFit(mem, listaProntos);
		break;
	default:
		break;
	}
	imprimeMemoria(mem);
	printf("\n Lista de Prontos \n");
	ImprimirLista(listaProntos);
	printf("\n Lista de IO \n");
	ImprimirLista(listaIO);
	/* * * * * * * * * * * * * * * * * * * * * * */
	// executar o processo
	IrInicioLista(listaProntos);
	tamProntos = LIS_ObterTamanho(listaProntos);
	tamIO = LIS_ObterTamanho(listaIO);
	aux =  (Processo*)LIS_ObterValor(listaProntos); // obtem o priemeiro elemento da lista de prontos
	while(tamProntos > 0)
	{
		if(!aux->naMemoria)	// se o processo não esta em memoria
		{
			LIS_AvancarElementoCorrente(listaProntos, 1);
			aux = (Processo*)LIS_ObterValor(listaProntos);
			continue;
		}
		procExec = aux;
		for(i = 0; i < 10; i++) // os 10 clocks de cpu
		{
			ImprimirEstado(&out, listaIO, procExec, mem, tempoTotal);
			clock(1); tempoTotal++;
			inxExec = procExec->t_exec;
			procExec->exec[inxExec]--;
			tamIO = LIS_ObterTamanho(listaIO);
			IrInicioLista(listaIO);
			for(j = 0; j < tamIO; j++) // diminui 1 de IO para todos q estao na lista de I/O
			{
				procIO = (Processo*)LIS_ObterValor(listaIO);
				inxIO = procIO->t_io;
				procIO->io[inxIO]--;
				if(procIO->io[inxIO] == 0) // seu tempo de io acabou
				{
					LIS_ExcluirElemento(listaIO); // retira da lista de io e insere-o na lista de prontos
					IrFinalLista(listaProntos);
					LIS_InserirElementoApos(listaProntos, procIO);
					procIO->t_io++;
				}
				LIS_AvancarElementoCorrente(listaIO, 1);
			}
			tamIO2 = LIS_ObterTamanho(listaIO);
			if(tamIO != tamIO2)
			{
				switch(met)
				{
				case 1:
					firstFit(mem, listaProntos);
					break;
				case 2:
					BestFit(mem, listaProntos);
					break;
				case 3:
					WorstFit(mem, listaProntos);
					break;
				case 4:
					NextFit(mem, listaProntos);
					break;
				default:
					break;
				}
			}
			getNext(listaProntos);
			if(procExec->exec[inxExec] == 0 || i == 9) // se o seu tempo de exec terminou entao retira da memoria
			{
				/* * * * * */	//imprimeMemoria(mem);
				LIS_ExcluirElemento(listaProntos);
				if(procExec->exec[inxExec] == 0) procExec->t_exec++; // se acabou um exec inteiro
				if(procExec->exec[inxExec] == 0 && procExec->t_io < procExec->qtdio) // se o processo terminou um exec e ainda tem io para fazer
				{
					IrFinalLista(listaIO);
					LIS_InserirElementoApos(listaIO, procExec);
				}
				// retira da memoria
				// se o processo ainda tem exec para fazer
				if(procExec->exec[inxExec] > 0)
				{
					IrFinalLista(listaProntos);
					LIS_InserirElementoApos(listaProntos, procExec);
				}
				seg = procExec->segAtual;
				procRetirado = RetiraProcessoMem(mem, seg);
				procRetirado->naMemoria = 0;
				switch(met)
				{
				case 1:
					firstFit(mem, listaProntos);
					break;
				case 2:
					BestFit(mem, listaProntos);
					break;
				case 3:
					WorstFit(mem, listaProntos);
					break;
				case 4:
					NextFit(mem, listaProntos);
					break;
				default:
					break;
				}
				break;
			}
			imprimeMemoria(mem);
			printf("\n Lista de Prontos \n");
			ImprimirLista(listaProntos);
			printf("\n Lista de IO \n");
			ImprimirLista(listaIO);
		} /* final dos 10 clocks*/
		imprimeMemoria(mem);
		printf("\n Lista de Prontos \n");
		ImprimirLista(listaProntos);
		printf("\n Lista de IO \n");
		ImprimirLista(listaIO);
		tamProntos = LIS_ObterTamanho(listaProntos);
		IrInicioLista(listaProntos);
		aux =  (Processo*)LIS_ObterValor(listaProntos);
	}
	tamIO = LIS_ObterTamanho(listaIO);
	while(tamIO > 0) // entao tem IO sobrando e ngm para executar
	{
		IrInicioLista(listaIO);
		clock(1);tempoTotal++;
		for(j = 0; j < tamIO; j++) // diminui 1 de IO para todos q estao na lista de I/O
		{
			procIO = (Processo*)LIS_ObterValor(listaIO);
			inxIO = procIO->t_io;
			procIO->io[inxIO]--;
			if(procIO->io[inxIO] == 0) // seu tempo de io acabou
			{
				LIS_ExcluirElemento(listaIO); // retira da lista de io e insere-o na lista de prontos
				IrFinalLista(listaProntos);
				LIS_InserirElementoApos(listaProntos, procIO);
				procIO->t_io++;
			}
			LIS_AvancarElementoCorrente(listaIO, 1);
		}
		tamIO = LIS_ObterTamanho(listaIO);
		tamProntos = LIS_ObterTamanho(listaProntos);
		imprimeMemoria(mem);
		printf("\n Lista de Prontos \n");
		ImprimirLista(listaProntos);
		printf("\n Lista de IO \n");
		ImprimirLista(listaIO);
		if(tamProntos > 0) // se alguem voltou par a lista de prontos...
			goto EXEC;
	}
	fclose(out);
	free(mem);
	free(vp);
	free(listaProntos);
	free(listaIO);
	return 0;
}
Exemple #26
0
   void LIS_Deturpar( void * pListaParm ,
                      int ModoDeturpar )
   {

	  static char EspacoLixo[ 256 ] =
             "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ;
            /* Espaço de dados lixo usado ao testar */
      LIS_tpLista * pLista = NULL ;

      if ( pListaParm == NULL )
      {
         return ;
      } /* if */

      pLista = ( LIS_tpLista * )( pListaParm ) ;

      switch ( ModoDeturpar ) {

      /* Anula ponteiro sucessor */

         case 0 :
         {

			  printf("%p\n",pLista->pElemCorr->pProx);
			 pLista->pElemCorr->pProx=NULL;
			 printf("%p\n",pLista->pElemCorr->pProx);

            break ;

         } /* fim ativa: Anula ponteiro sucessor */

      /* Anula ponteiro predecessor */

         case 1 :
         {

 			  printf("%p\n",pLista->pElemCorr->pAnt);
			 pLista->pElemCorr->pAnt=NULL;
			 printf("%p\n",pLista->pElemCorr->pAnt);

            break ;

         } /* fim ativa: Anula ponteiro predecessor */

	  /* Faz sucessor apontar para lixo  */

         case 2 :
         {

 			 printf("%p\n",pLista->pElemCorr->pProx);
			 pLista->pElemCorr->pProx=(tpElemLista *)(EspacoLixo);
			 printf("%p\n",pLista->pElemCorr->pProx);

            break ;

         } /* fim ativa: Faz sucessor apontar para lixo  */

	  /* Faz predecessor apontar para lixo */

         case 3 :
         {

 			
			 pLista->pElemCorr->pAnt=(tpElemLista *)(EspacoLixo);

            break ;

         } /* fim ativa: Faz predecessor apontar para lixo */

	   /* Destaca vértice */

		 case 4 :
         {

 			pLista->pElemCorr->pValor=NULL;
			LIS_ExcluirElemento(pLista);

            break ;

         } /* fim ativa: Destaca vértice */


      /* ModoDetrupar desconhecido */

         default :
		 {
			
			printf("ModoDeturpar desconhecido");
         
            break ;

         } /* fim ativa: ModoDetrupar desconhecido */

      } /* fim seleciona: Raiz de GRF  &Deturpar grafo */

   } /* Fim função: GRF  &Deturpar grafo */
Exemple #27
0
TAB_tpCondRet TAB_MoverPeca( TAB_tppTabuleiro pTab, int casaOrigem, int casaDestino ) 
{
	tppPeca pecatemp1, pecatemp2;
	char cor;
	LIS_tppLista listatemp;
	int  mov = casaDestino - casaOrigem;

	// Checa a validade das casas de origem e destino
	if((casaOrigem < 0) || (casaOrigem > 23))
	{
		printf("casaOrigem inválida \n");
		return TAB_CondRetErro;
	}
	if((casaDestino < 0) || (casaDestino > 23))
	{
		printf("casaDestino inválida \n");
		return TAB_CondRetErro;
	}

	// Ir para a casa de origem
	IrInicioLista(pTab->Casas);
	LIS_AvancarElementoCorrente(pTab->Casas, casaOrigem);

	// Obter referência para a lista nela armazenada
	listatemp = (LIS_tppLista)LIS_ObterValor(pTab->Casas);

	// Obter a cor da peca na lista temp
	pecatemp1 = (tppPeca)LIS_ObterValor(listatemp);

	// se pecatemp1 == NULL entao a lista está vazia
	if(pecatemp1 == NULL)
	{
		printf("casa de origem esta vazia \n");
		return TAB_CondRetErro;
	}
	else // se nao
	{
		Pec_ObterCor(pecatemp1, &cor);
	}

	// Excluir uma peça da lista temp
	if(LIS_ExcluirElemento(listatemp) != LIS_CondRetOK)
	{
		printf("Erro ao excluir peca da casa de orgiem\n");
		return TAB_CondRetErro;
	}

	// Avança para a casa destino.
	LIS_AvancarElementoCorrente(pTab->Casas, mov);

	// Obtem a referencia para a lista nela armazenada
	listatemp = (LIS_tppLista)LIS_ObterValor(pTab->Casas);

	// Criar uma peça com a mesma cor q a peça antiga
	if(Pec_CriarPeca(&pecatemp2, cor) != Pec_CondRetOK)
	{
		printf("Erro ao criar a peca na casa destino \n");
		return TAB_CondRetErro;
	}

	// Adiciona esta peça na casa de destino
	if(LIS_InserirElementoApos(listatemp, pecatemp2) != LIS_CondRetOK)
	{
		printf("Erro ao adicionar peca na casa destino \n");
		return TAB_CondRetErro;
	}

	return TAB_CondRetOK;
}
Exemple #28
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      int inxLista  = -1 ,
          numLidos   = -1 ,
          CondRetEsp = -1  ;

      TST_tpCondRet CondRet ;

	  int CondRetObtido = LIS_CondRetOK;
	  int det, falhasEsperadas, falhasObtidas;

      char   StringDado[  DIM_VALOR ] ;
      char * pDado ;

      int ValEsp = -1 ;

      int i,num ;

      int numElem = -1 ;

      StringDado[ 0 ] = 0 ;

      /* Efetuar reset de teste de lista */

         if ( strcmp( ComandoTeste , RESET_LISTA_CMD ) == 0 )
         {

            for( i = 0 ; i < DIM_VT_LISTA ; i++ )
            {
               vtListas[ i ] = NULL ;
            } /* for */

            return TST_CondRetOK ;

         } /* fim ativa: Efetuar reset de teste de lista */

      /* Testar CriarLista */

         else if ( strcmp( ComandoTeste , CRIAR_LISTA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                       &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            vtListas[ inxLista ] =
                 LIS_CriarLista( DestruirValor ) ;

            return TST_CompararPonteiroNulo( 1 , vtListas[ inxLista ] ,
               "Erro em ponteiro de nova lista."  ) ;

         } /* fim ativa: Testar CriarLista */

      /* Testar Esvaziar lista lista */

         else if ( strcmp( ComandoTeste , ESVAZIAR_LISTA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                               &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_EsvaziarLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Esvaziar lista lista */

      /* Testar Destruir lista */

         else if ( strcmp( ComandoTeste , DESTRUIR_LISTA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                               &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_DestruirLista( vtListas[ inxLista ] ) ;
            vtListas[ inxLista ] = NULL ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Destruir lista */

      /* Testar inserir elemento antes */

         else if ( strcmp( ComandoTeste , INS_ELEM_ANTES_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "isi" ,
                       &inxLista , StringDado , &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado = ( char * ) malloc( strlen( StringDado ) + 1 ) ;
            if ( pDado == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            strcpy( pDado , StringDado ) ;


            CondRet = LIS_InserirElementoAntes( vtListas[ inxLista ] , pDado ) ;

            if ( CondRet != LIS_CondRetOK )
            {
               free( pDado ) ;
            } /* if */

            return TST_CompararInt( CondRetEsp , CondRet ,
                     "Condicao de retorno errada ao inserir antes."                   ) ;

         } /* fim ativa: Testar inserir elemento antes */

      /* Testar inserir elemento apos */

         else if ( strcmp( ComandoTeste , INS_ELEM_APOS_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "isi" ,
                       &inxLista , StringDado , &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado = ( char * ) malloc( strlen( StringDado ) + 1 ) ;
            if ( pDado == NULL )
            {
               return TST_CondRetMemoria ;
            } /* if */

            strcpy( pDado , StringDado ) ;


            CondRet = LIS_InserirElementoApos( vtListas[ inxLista ] , pDado ) ;

            if ( CondRet != LIS_CondRetOK )
            {
               free( pDado ) ;
            } /* if */

            return TST_CompararInt( CondRetEsp , CondRet ,
                     "Condicao de retorno errada ao inserir apos."                   ) ;

         } /* fim ativa: Testar inserir elemento apos */

      /* Testar excluir simbolo */

         else if ( strcmp( ComandoTeste , EXC_ELEM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                  &inxLista , &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp ,
                      LIS_ExcluirElemento( vtListas[ inxLista ] ) ,
                     "Condição de retorno errada ao excluir."   ) ;

         } /* fim ativa: Testar excluir simbolo */

      /* Testar obter valor do elemento corrente */

         else if ( strcmp( ComandoTeste , OBTER_VALOR_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "isi" ,
                       &inxLista , StringDado , &ValEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            pDado = ( char * ) LIS_ObterValor( vtListas[ inxLista ] ) ;

            if ( ValEsp == 0 )
            {
               return TST_CompararPonteiroNulo( 0 , pDado ,
                         "Valor não deveria existir." ) ;
            } /* if */

            if ( pDado == NULL )
            {
               return TST_CompararPonteiroNulo( 1 , pDado ,
                         "Dado tipo um deveria existir." ) ;
            } /* if */

            return TST_CompararString( StringDado , pDado ,
                         "Valor do elemento errado." ) ;

         } /* fim ativa: Testar obter valor do elemento corrente */

      /* Testar ir para o elemento inicial */

         else if ( strcmp( ComandoTeste , IR_INICIO_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" , &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            IrInicioLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar ir para o elemento inicial */

      /* LIS  &Ir para o elemento final */

         else if ( strcmp( ComandoTeste , IR_FIM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" , &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            IrFinalLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: LIS  &Ir para o elemento final */

      /* LIS  &Avançar elemento */

         else if ( strcmp( ComandoTeste , AVANCAR_ELEM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "iii" , &inxLista , &numElem ,
                                &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp , LIS_AvancarElementoCorrente( vtListas[ inxLista ] , numElem ) ,
                      "Condicao de retorno errada ao avancar" ) ;

         } /* fim ativa: LIS  &Avançar elemento */
		 /* LIS &Testar Obter Tamanho Lista */
		 else if (strcmp ( ComandoTeste , OBTER_TAMANHO_CMD ) == 0 )
		 {
			 numLidos = LER_LerParametros( "iii" ,&inxLista,&ValEsp, &CondRetEsp ) ;

			if ( ( numLidos != 3 )||( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

			CondRetObtido = LIS_ObterTamanho( vtListas[ inxLista ], &num );

			CondRet = TST_CompararInt( ValEsp , num ,"Valor do elemento errado, diferente do esperado" ) ;

			if ( CondRet != TST_CondRetOK )
               return CondRet ;

						return TST_CondRetOK;
		 }  /* Fim testar Obter Tamanho */
#ifdef _DEBUG
		 /* Testar Deturpar */
		 else if (strcmp ( ComandoTeste , DETURPA_CMD ) == 0 )
		 {
			 numLidos = LER_LerParametros( "ii" ,&inxLista, &det) ;

			if ( numLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

			DeturpaLista(vtListas[ inxLista ], det);

			return TST_CondRetOK;
		 }
		 else if (strcmp ( ComandoTeste , VERIFICA_CMD ) == 0 )
		 {
			 numLidos = LER_LerParametros( "ii" ,&inxLista, &falhasEsperadas) ;

			if ( numLidos != 2 )
            {
               return TST_CondRetParm ;
            } /* if */

			verificaLista(vtListas[ inxLista ], &falhasObtidas);

			CondRet = TST_CompararInt( falhasEsperadas , falhasObtidas ,"Numero de falhas esperadas diferente de obtida" ) ;
			if ( CondRet != TST_CondRetOK )
               return CondRet ;

			return TST_CondRetOK;
		 }
#endif
		 return TST_CondRetNaoConhec ;

   } /* Fim função: TLIS &Testar lista */
Exemple #29
0
GRA_tpCondRet GRA_ExcluirAresta(char pVertOrig , char pVertDest , GRA_tppGrafo pGrafo)
{
	tpVerticeGrafo * pVertO;
	tpVerticeGrafo * pVertD;
	tpArestaGrafo * pAres;
	
	pVertO = GRA_BuscarVertice(pGrafo, pVertOrig);
	if(pVertO == NULL){
		return GRA_CondRetNaoAchou ;
	} /* if */

	pVertD = GRA_BuscarVertice(pGrafo, pVertDest);
	if(pVertD == NULL){
		return GRA_CondRetNaoAchou ;
	} /* if */

	pGrafo->pCorrente = pVertO;

	ListaRetCaminho = LIS_IrInicioLista(pVertO->pVerSuc);
		
	while(ListaRetCaminho==LIS_CondRetOK || ListaRetCaminho==LIS_CondRetFimLista){
			
		LIS_ObterValor (pVertO->pVerSuc , (void**)&pAres);

		if(pAres->pVerticeDest->pIdVertice == pVertDest){

			GRA_excluirValorListaAresta(pAres);

			LIS_ExcluirElemento(pVertO->pVerSuc);

			break;

		} /* if */
		if(ListaRetCaminho == LIS_CondRetFimLista){
			break;
		} /* if */
		ListaRetCaminho = LIS_AvancarElementoCorrente(pVertO->pVerSuc, 1);

	} /* while */

	pGrafo->pCorrente = pVertD;

	ListaRetCaminho = LIS_IrInicioLista(pVertD->pVerAnt);
		
	while(ListaRetCaminho==LIS_CondRetOK || ListaRetCaminho==LIS_CondRetFimLista){
			
		LIS_ObterValor (pVertD->pVerAnt , (void**)&pVertO);

		if(pVertO->pIdVertice == pVertOrig){

			LIS_ExcluirElemento(pVertD->pVerAnt);

			break;

		} /* if */
		if(ListaRetCaminho == LIS_CondRetFimLista){
			break;
		} /* if */
		ListaRetCaminho = LIS_AvancarElementoCorrente(pVertD->pVerAnt, 1);

	} /* while */


	return GRA_CondRetOK;
}
Exemple #30
0
   TST_tpCondRet TST_EfetuarComando( char * ComandoTeste )
   {

      int inxLista  = -1 ,
          numLidos   = -1 ,
          CondRetEsp = -1  ;

      TST_tpCondRet CondRet ;

      char   CharDado ;

      int ValEsp = -1 ;

      int i ;

      int numElem = -1 ;

      /* Efetuar reset de teste de lista */

         if ( strcmp( ComandoTeste , RESET_LISTA_CMD ) == 0 )
         {

            for( i = 0 ; i < DIM_VT_LISTA ; i++ )
            {
               vtListas[ i ] = NULL ;
            } /* for */

            return TST_CondRetOK ;

         } /* fim ativa: Efetuar reset de teste de lista */

      /* Testar CriarLista */

         else if ( strcmp( ComandoTeste , CRIAR_LISTA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                       &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            vtListas[ inxLista ] =
                 LIS_CriarLista( ) ;

            return TST_CompararPonteiroNulo( 1 , vtListas[ inxLista ] ,
               "Erro em ponteiro de nova lista."  ) ;

         } /* fim ativa: Testar CriarLista */

      /* Testar Esvaziar lista */

         else if ( strcmp( ComandoTeste , ESVAZIAR_LISTA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                               &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_EsvaziarLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Esvaziar lista lista */

      /* Testar Destruir lista */

         else if ( strcmp( ComandoTeste , DESTRUIR_LISTA_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" ,
                               &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )))
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_DestruirLista( vtListas[ inxLista ] ) ;
            vtListas[ inxLista ] = NULL ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar Destruir lista */

      /* Testar inserir elemento antes */

         else if ( strcmp( ComandoTeste , INS_ELEM_ANTES_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ici" ,
                       &inxLista , &CharDado , &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            CondRet = LIS_InserirElementoAntes( vtListas[ inxLista ] , CharDado ) ;

            return TST_CompararInt( CondRetEsp , CondRet ,
                     "Condicao de retorno errada ao inserir antes."                   ) ;

         } /* fim ativa: Testar inserir elemento antes */

      /* Testar inserir elemento apos */

         else if ( strcmp( ComandoTeste , INS_ELEM_APOS_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ici" ,
                       &inxLista , &CharDado , &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            CondRet = LIS_InserirElementoApos( vtListas[ inxLista ] , CharDado ) ;

            return TST_CompararInt( CondRetEsp , CondRet ,
                     "Condicao de retorno errada ao inserir apos."                   ) ;

         } /* fim ativa: Testar inserir elemento apos */

      /* Testar excluir simbolo */

         else if ( strcmp( ComandoTeste , EXC_ELEM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                  &inxLista , &CondRetEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp ,
                      LIS_ExcluirElemento( vtListas[ inxLista ] ) ,
                     "Condição de retorno errada ao excluir."   ) ;

         } /* fim ativa: Testar excluir simbolo */

      /* Testar obter valor do elemento corrente */

         else if ( strcmp( ComandoTeste , OBTER_VALOR_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ic" ,
                       &inxLista , &CharDado ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

			return TST_CompararChar( CharDado,
					LIS_ObterValor( vtListas[ inxLista ] ),
					"Valor do elemento corrente está errado." );

         } /* fim ativa: Testar obter valor do elemento corrente */

      /* Testar ir para o elemento inicial */

         else if ( strcmp( ComandoTeste , IR_INICIO_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" , &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_IrInicioLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: Testar ir para o elemento inicial */

      /* LIS  &Ir para o elemento final */

         else if ( strcmp( ComandoTeste , IR_FIM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "i" , &inxLista ) ;

            if ( ( numLidos != 1 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            LIS_IrFinalLista( vtListas[ inxLista ] ) ;

            return TST_CondRetOK ;

         } /* fim ativa: LIS  &Ir para o elemento final */

      /* LIS  &Avançar elemento */

         else if ( strcmp( ComandoTeste , AVANCAR_ELEM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "iii" , &inxLista , &numElem ,
                                &CondRetEsp ) ;

            if ( ( numLidos != 3 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

            return TST_CompararInt( CondRetEsp ,
                      LIS_AvancarElementoCorrente( vtListas[ inxLista ] , numElem ) ,
                      "Condicao de retorno errada ao avancar" ) ;

         } /* fim ativa: LIS  &Avançar elemento */
		 
      /* Testar obter numero de elementos */

         else if ( strcmp( ComandoTeste , OBTER_NUM_ELEM_CMD ) == 0 )
         {

            numLidos = LER_LerParametros( "ii" ,
                       &inxLista , &ValEsp ) ;

            if ( ( numLidos != 2 )
              || ( ! ValidarInxLista( inxLista , NAO_VAZIO )) )
            {
               return TST_CondRetParm ;
            } /* if */

			return TST_CompararInt( ValEsp,
					LIS_ObterNumElem( vtListas[ inxLista ] ),
					"Numero de elementos da lista esta errado." );

         } /* fim ativa: Testar obter numero de elementos */
     

      return TST_CondRetNaoConhec ;

   } /* Fim função: TLIS &Testar lista */