void get_pair_by_id(GRA_tppGrafo pGrafo, int idAresta, tpVertice ** u, tpVertice ** v){ tpAresta * aresta = NULL; tpVertice * vertice = NULL; LIS_IrInicioLista( pGrafo->vertices ); // Para cada vértice do{ vertice = (tpVertice*)LIS_ObterValor( pGrafo->vertices ) ; if(vertice == NULL) break; LIS_IrInicioLista( vertice->pNode->arestas ) ; // Procura em todos os seus vizinhos do{ aresta = (tpAresta*)LIS_ObterValor( vertice->pNode->arestas ) ; if(aresta == NULL){ continue; } if ( aresta->id == idAresta ){ *u = vertice ; *v = aresta->pVizinho ; break; } }while(LIS_AvancarElementoCorrente( vertice->pNode->arestas , 1) == LIS_CondRetOK ); }while ( LIS_AvancarElementoCorrente( pGrafo->vertices , 1) == LIS_CondRetOK ) ; }
int ListaDePassosSaoIguais(LIS_tppLista pPassos1, LIS_tppLista pPassos2) { PAS_tppPasso pPasso1; PAS_tppPasso pPasso2; LIS_tpCondRet ret1 = LIS_CondRetOK; LIS_tpCondRet ret2 = LIS_CondRetOK; LIS_IrInicioLista(pPassos1); LIS_IrInicioLista(pPassos2); while (ret1 == LIS_CondRetOK && ret2 == LIS_CondRetOK) { int saoIguais; LIS_ObterValor(pPassos1, (void **) &pPasso1); LIS_ObterValor(pPassos2, (void **) &pPasso2); PAS_CompararPassos(pPasso1, pPasso2, &saoIguais); if (!saoIguais) { return FALSE; } ret1 = LIS_AvancarElementoCorrente(pPassos1, 1); ret2 = LIS_AvancarElementoCorrente(pPassos2, 1); } if (ret1 != ret2) { return FALSE; } return TRUE; }
void GRA_Del (Graph *g) { #ifdef _DEBUG AssertGraph(g); #endif /* _DEBUG */ CNT_CONTAR("GRA_Del - Inicializao"); IrInicioLista ( g->nodes ); if ( !g->currentNode || !LIS_AvancarElementoCorrente ( g->nodes , 1)){ CNT_CONTAR("GRA_Del - Grafo vazio"); return; } IrInicioLista ( g->nodes ); do { CNT_CONTAR("GRA_Del - Deletando nos"); g->currentNode = LIS_ObterValor( g->nodes ); GRA_DelNode( g ); } while ( LIS_AvancarElementoCorrente ( g->nodes , 1) == LIS_CondRetOK ); /* == 0 ); */ CNT_CONTAR("GRA_Del - Destruindo, finalizao"); LIS_DestruirLista( g->nodes ); free(g); return; }
/*************************************************************************** * * Função: TAB &Imprimir estado atual de um tabuleiro * ****/ void TAB_imprimir(Tabuleiro *tabuleiro) { int x, y; //Assertivas de entrada #ifdef _DEBUG if(tabuleiro == NULL) printf("\n Não foi possível imprimir o tabuleiro (não existe) \n"); #endif LIS_IrFinalLista(tabuleiro->lista); for(y = TabuleiroAltura - 1; y >= 0; --y) { LIS_tppLista lista; printf("%d|", y+1); lista = (LIS_tppLista)LIS_ObterValor(tabuleiro->lista); LIS_IrInicioLista(lista); for(x = 0; x < TabuleiroLargura; ++x) { Peca *peca = LIS_ObterValor(lista); if(peca) PEC_imprimir(peca); else printf(" |"); LIS_AvancarElementoCorrente(lista, 1); } printf("\n"); LIS_AvancarElementoCorrente(tabuleiro->lista, -1); } printf(" |A|B|C|D|E|F|G|H|\n"); }/* Fim função: TAB &Imprimir estado atual de um tabuleiro */
void TAB_inicializar(Tabuleiro *tabuleiro, char idJogador1, char idJogador2) { int x, y; //Assertivas de entrada #ifdef _DEBUG if(tabuleiro == NULL){ printf("\n tabuleiro não existe \n"); return; } if(idJogador1 != 'x' || idJogador2 != 'o'){ printf("\n Erro na associação de caracteres correspondentes ao jogador1 e/ou jogador2 \n"); return; } #endif LIS_IrInicioLista(tabuleiro->lista); for(y = 0; y < TabuleiroAltura; ++y) { LIS_tppLista lista = (LIS_tppLista)LIS_ObterValor(tabuleiro->lista); LIS_IrInicioLista(lista); for(x = 0; x < TabuleiroLargura; ++x) { Peca *peca = NULL; if(y < 2 && (x + y) % 2 == 1) peca = PEC_criar(PecaNormal, idJogador1); else if(y > TabuleiroAltura - 3 && (x + y) % 2 == 1) peca = PEC_criar(PecaNormal, idJogador2); LIS_SetarValor(lista, peca); LIS_AvancarElementoCorrente(lista, 1); } LIS_AvancarElementoCorrente(tabuleiro->lista, 1); } }/* Fim função: TAB &Inicializar tabuleiro para início de uma partida */
LIS_tppLista achaCoor( LIS_tppLista Tab, int x, int y) { LIS_tppLista Col; LIS_AvancarElementoCorrente(Tab, x); Col = (LIS_tppLista) LIS_ObterValor(Tab); LIS_AvancarElementoCorrente(Col, y); return Col; }
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; }
GRA_tpCondRet GRA_ObterValores( GRA_tppGrafo pGrafo, LIS_tppLista pValores ) { LIS_tppLista vertices; tpVertice* vertice; void* valor; vertices = pGrafo->vertices; LIS_IrInicioLista(vertices); do{ valor = LIS_ObterValor(vertices); LIS_InserirElementoApos(pValores,valor); LIS_AvancarElementoCorrente(pValores,1); }while(LIS_AvancarElementoCorrente(vertices,1) == LIS_CondRetOK); }
LIS_tppLista MTZ_achaCoor(LIS_tppLista Tab, int x, int y) { LIS_tppLista coor;// = LIS_CriarLista(0);/* Armazena copia da coluna*/ LIS_AvancarElementoCorrente(Tab, x); coor = (LIS_tppLista) LIS_ObterValor(Tab); IrInicioLista(coor); LIS_AvancarElementoCorrente(coor, y); IrInicioLista(Tab); return coor; }
GRA_tpCondRet GRA_BuscarVertice( GRA_tppGrafo pGrafo , int* idVertice , int predicado(void* pDado, void* _parametro), void* parametro ) { LIS_tppLista vertices; tpVertice* vertice; vertices = pGrafo->vertices; if(LIS_NumeroDeElementos(vertices) == 0){ *idVertice = -1; return GRA_CondRetGrafoVazio; } LIS_IrInicioLista(vertices); do { vertice = (tpVertice*)LIS_ObterValor(vertices); if (predicado(vertice->pNode->pValor, parametro)) { *idVertice = vertice->id; return GRA_CondRetOK; } } while (LIS_AvancarElementoCorrente(vertices, 1) == LIS_CondRetOK); return GRA_CondRetNaoEhVertice; }
GRA_tpCondRet GRA_DestruirGrafo( GRA_tppGrafo pGrafo ) { tpVertice* pVertice = NULL; #ifdef _DEBUG assert( pGrafo != NULL ) ; #endif LIS_DestruirLista(pGrafo->componentes); //Lista que não mexe com "ninguém" LIS_IrInicioLista(pGrafo->vertices); do { pVertice = (tpVertice *)LIS_ObterValor(pGrafo->vertices); if(pVertice == NULL) continue; if (pVertice->pNode->pValor != NULL && pGrafo->ExcluirValor != NULL) { pGrafo->ExcluirValor(pVertice->pNode->pValor); } LIS_DestruirLista(pVertice->pNode->arestas); free(pVertice->pNode); } while(LIS_AvancarElementoCorrente(pGrafo->vertices, 1) == LIS_CondRetOK); LIS_DestruirLista(pGrafo->vertices); free( pGrafo ) ; return GRA_CondRetOK; }
static tpVertice* ObterOrigem (GRA_tppGrafo grafo, tpVertice* v) { tpVertice** us = NULL; //Vetor com componentes a iterar; tpVertice* u = NULL; LIS_tppLista origens = grafo->componentes; int i = 0; LIS_IrInicioLista(grafo->vertices); LIS_IrInicioLista(origens); if (LIS_ProcurarValor(origens, v) == LIS_CondRetOK) { return v; //é a origem da própria componente } if(LIS_NumeroDeElementos(origens) > 0) { us = (tpVertice**) calloc(LIS_NumeroDeElementos(origens), sizeof(tpVertice*)); LIS_IrInicioLista(origens); do { u = (tpVertice *)LIS_ObterValor(origens); if(u == NULL) break; us[i] = u; i++; } while(LIS_AvancarElementoCorrente(origens, 1) == LIS_CondRetOK); for ( i;i; i--) { if (BFS(us[i-1],v) == 1) { u = us[i-1]; } } free(us); } return u; }
PIL_tpCondRet PIL_VerCarta( PIL_tppPilha pPilha , CAR_tppCarta * pCarta , int posicao ) { LIS_tpCondRet Ret ; *pCarta = NULL ; if ( posicao < 0 ) { return PIL_CondRetParamIncorreto ; } LIS_IrFinalLista( pPilha->pListaCartas ) ; Ret = LIS_AvancarElementoCorrente( pPilha->pListaCartas , - posicao ) ; if ( Ret == LIS_CondRetFimLista ) { return PIL_CondRetFimPilha ; } if ( Ret == LIS_CondRetListaVazia ) { return PIL_CondRetPilhaVazia ; } LIS_ObterValor( pPilha->pListaCartas , pCarta ) ; return PIL_CondRetOK ; }/* Fim função: PIL VerCarta */
/* 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; }
LIS_tpCondRet LIS_InserirElementoOrdenado( LIS_tppLista pLista , void *pValor, int (*pComp) (void *a, void *b)) { LIS_tpElemLista *pElem ; #ifdef _DEBUG assert( pLista != NULL ) ; #endif /* Criar elemento a inserir antes */ pElem = CriarElemento( pLista , pValor ) ; if ( pElem == NULL ) { return LIS_CondRetFaltouMemoria ; } /* if */ /* Ir para o comeco da lista */ IrInicioLista (pLista); /* Percorrer a lista até encontrar um valor superior ou igual */ while (LIS_AvancarElementoCorrente(pLista, 1) != LIS_CondRetFimLista) { if (pComp(LIS_ObterValor(pLista), pValor) > 0) { break ; } /* if */ } /* while */ /* Encadear o elemento antes do elemento superior */ return LIS_InserirElementoAntes(pLista, pValor); } /* Fim funcao: LIS &Inserir elemento antes */
int WorstFit (Memory *mem, LIS_tppLista lisProntos){ Processo *aux; int cnt = 0, fail = 0, i; IrInicioLista(lisProntos); aux = (Processo*)LIS_ObterValor(lisProntos); cnt = LIS_ObterTamanho(lisProntos); fail = 1; while (cnt > 0) { int diferenca = 0; int BestInd = -1; for (i = 0; i < 5; i++) { if ((aux->tamanho <= mem->s[i].tam) && (mem->s[i].proc == NULL) && (aux->naMemoria == 0)) // se o tamanho do process é menor q o segmento da memoria { if (mem->s[i].tam - aux->tamanho >= diferenca){ BestInd = i; diferenca = mem->s[i].tam - aux->tamanho; } } } if (BestInd != -1){ InsereProcessosMem(mem, aux, mem->s[BestInd].tam); fail = 0; } LIS_AvancarElementoCorrente(lisProntos, 1); aux = (Processo*)LIS_ObterValor(lisProntos); cnt--; } return fail; }
void *GRA_NodesGetNext (Graph *g) { void *ret; LIS_tppLista l; CNT_CONTAR("GRA_NodesGetNext - inicio"); #ifdef _DEBUG AssertGraph(g); #endif /* _DEBUG */ if (!g->currentNode){ return NULL; } CNT_CONTAR("GRA_NodesGetNext - guardando g->nodes"); l = g->nodes; if (!l){ CNT_CONTAR("GRA_NodesGetNext - Nao existe g->nodes"); return NULL; } CNT_CONTAR("GRA_NodesGetNext - Obtendo dado"); ret = ((Node*)LIS_ObterValor (LIS_ObterValor(l)))->data; if (g->nodesOld == ret){ /* Se esse dado ja' repitiu, ja terminou a lista */ CNT_CONTAR("GRA_NodesGetNext - Dado repetido, fim da lista"); return NULL; } CNT_CONTAR("GRA_NodesGetNext - Avanando elemento corrente"); g->nodesOld = ret; LIS_AvancarElementoCorrente (l, 1); #ifdef _DEBUG AssertGraph(g); #endif /* _DEBUG */ CNT_CONTAR("GRA_NodesGetNext - Finalizando"); return ret; }
int firstFit(Memory *mem, LIS_tppLista lisProntos) { Processo *aux; int cnt = 0, fail = 0,i; IrInicioLista(lisProntos); aux = (Processo*)LIS_ObterValor(lisProntos); cnt = LIS_ObterTamanho(lisProntos); fail = 1; while(cnt > 0) { for(i = 0; i < 5; i++) { if((aux->tamanho <= mem->s[i].tam) && (mem->s[i].proc == NULL) && (aux->naMemoria == 0)) // se o tamanho do process é menor q o segmento da memoria { InsereProcessosMem(mem, aux, mem->s[i].tam); fail = 0; break; } } LIS_AvancarElementoCorrente(lisProntos, 1); aux = (Processo*)LIS_ObterValor(lisProntos); cnt--; } return fail; }
GRA_tpCondRet GRA_DefinirCorrente(GRA_tppGrafo pGrafo, char IdVert) { tpVerticeGrafo * pVerticeBusca ; ListaRet = LIS_IrInicioLista(pGrafo->pListaVertices); while(ListaRet == LIS_CondRetOK || ListaRet == LIS_CondRetFimLista){ LIS_ObterValor (pGrafo->pListaVertices , (void**)&pVerticeBusca); if(pVerticeBusca->pIdVertice == IdVert){ pGrafo->pCorrente = pVerticeBusca; return GRA_CondRetOK; } /* if */ if(ListaRet==LIS_CondRetFimLista){ break; } /* if */ ListaRet = LIS_AvancarElementoCorrente(pGrafo->pListaVertices, 1); } /* while */ return GRA_CondRetNaoAchou ; }
int ChecaVerticeExiste(GRA_tppGrafo pGrafo, char Vert) { tpVerticeGrafo * pVertice; if(pGrafo==NULL){ return 0; } /* if */ ListaRetCaminho=LIS_IrInicioLista(pGrafo->pListaVertices); while(ListaRetCaminho==LIS_CondRetOK || ListaRetCaminho==LIS_CondRetFimLista){ LIS_ObterValor(pGrafo->pListaVertices , (void**)&pVertice); if(pVertice->pIdVertice == Vert){ return 1; } /* if */ if(ListaRetCaminho == LIS_CondRetFimLista){ return 0; } /* if */ ListaRetCaminho = LIS_AvancarElementoCorrente(pGrafo->pListaVertices, 1); } /* while */ pVertice = NULL; return 0; } /* Fim função: GRA &Checa se vertice existe */
int ChecaArestaExiste(tpVerticeGrafo * pVertice , char * String, char Dest) { tpArestaGrafo * pAres ; if(pVertice==NULL){ return 0; } /* if */ ListaRetCaminho=LIS_IrInicioLista(pVertice->pVerSuc); while(ListaRetCaminho==LIS_CondRetOK || ListaRetCaminho==LIS_CondRetFimLista){ LIS_ObterValor(pVertice->pVerSuc , (void**)&pAres); if(strcmp(pAres->Nome , String)==0 && pAres->pVerticeDest->pIdVertice == Dest){ return 1; } /* if */ if(ListaRetCaminho == LIS_CondRetFimLista){ return 0; } /* if */ ListaRetCaminho = LIS_AvancarElementoCorrente(pVertice->pVerSuc, 1); } /* while */ pAres = NULL; return 0; } /* Fim função: GRA &Checa se aresta existe */
/*************************************************************************** * * Função: TAB &mover uma peça no tabuleiro * ****/ int TAB_verificaVencedor(Tabuleiro *tabuleiro, char idJogador1, char idJogador2) { int x, y; int existe1 = 0, existe2 = 0; //Assertivas de entrada #ifdef _DEBUG if(!tabuleiro) printf("\n tabuleiro não existe \n"); if(idJogador1 != 'x' || idJogador2 != 'o') printf("\n Erro na associação de caracteres correspondentes ao jogador1 e/ou jogador2 \n"); #endif LIS_IrFinalLista(tabuleiro->lista); for(y = TabuleiroAltura - 1; y >= 0; --y) { LIS_tppLista lista = (LIS_tppLista)LIS_ObterValor(tabuleiro->lista); LIS_IrInicioLista(lista); for(x = 0; x < TabuleiroLargura; ++x) { Peca *peca = LIS_ObterValor(lista); if(peca) { if(PEC_obterCaracter(peca) == idJogador1) existe1 = 1; else if(PEC_obterCaracter(peca) == idJogador2) existe2 = 1; if(existe1 && existe2) // existe peca dos 2 jogadores no tabuleiro. jogo continua return -1; } LIS_AvancarElementoCorrente(lista, 1); } LIS_AvancarElementoCorrente(tabuleiro->lista, -1); } if(existe1 && !existe2) // so ha pecas do jogador 1 presentes. ele ganhou return 0; if(!existe1 && existe2) // so ha pecas do jogador 2 presentes. ele ganhou return 1; //Assertivas de saida #ifdef _DEBUG printf("Caso indefinido em TAB_verificaVencedor"); #endif return -2; }/* Fim função: TAB verifica vencedor */
MES_tpCondRet MES_ExibirCartas( LIS_tppLista pCartas ) { int i = 1 ; BAR_tppCarta carta ; LIS_tpCondRet retornoLista ; char* valor = ( char* ) malloc( 7 * sizeof( char ) ) ; char* naipe = ( char* ) malloc( 8 * sizeof( char ) ) ; if ( valor == NULL || naipe == NULL ) { return MES_CondRetFaltouMemoria ; } if ( pCartas == NULL ) { return MES_CondRetListaNaoExiste ; } LIS_IrInicioLista( pCartas ) ; carta = (BAR_tppCarta) LIS_ObterValor( pCartas ) ; if ( carta == NULL ) { return MES_CondRetListaVazia ; } BAR_ObterValor( carta , valor ) ; BAR_ObterNaipe( carta , naipe ) ; printf( "\n%d - %s de %s" , i , valor , naipe ) ; retornoLista = LIS_AvancarElementoCorrente( pCartas , 1 ) ; while ( retornoLista != LIS_CondRetFimLista ) { i++ ; carta = (BAR_tppCarta) LIS_ObterValor( pCartas ) ; BAR_ObterValor( carta , valor ) ; BAR_ObterNaipe( carta , naipe ) ; printf( "\n%d - %s de %s" , i , valor , naipe ) ; retornoLista = LIS_AvancarElementoCorrente( pCartas , 1 ) ; } free( valor ) ; free( naipe ) ; return MES_CondRetOK ; }
void getNext(LIS_tppLista lisProc) { Processo *aux; IrInicioLista(lisProc); aux = (Processo*)LIS_ObterValor(lisProc); while(aux->naMemoria == 0) { LIS_AvancarElementoCorrente(lisProc, 1); aux = (Processo*)LIS_ObterValor(lisProc); } }
/*********************************************************************** * * $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; }
/*********************************************************************** * * $FC Função: MEN getbycmd * * $ED Descrição da Função * Obtem ponteiro pra Opcao a partir do seu caracter de comando. * ***********************************************************************/ static MEN_tppOpcao getbycmd(MEN_tppMenus m, int id, char cmd) { MEN_tppMenu menu; GRA_ObterValor(m->grafo,id,(void**)&menu); LIS_IrInicioLista(menu->opcoes); do{ MEN_tppOpcao o = (MEN_tppOpcao)LIS_ObterValor(menu->opcoes); if(o->cmd == cmd){ return o; } } while(LIS_AvancarElementoCorrente(menu->opcoes,1)==LIS_CondRetOK); }
void ImprimirLista(LIS_tppLista lisProntos) { int tam, i; Processo *aux; IrInicioLista(lisProntos); tam = LIS_ObterTamanho(lisProntos); for(i = 0; i < tam; i++) { aux = (Processo*)LIS_ObterValor(lisProntos); imprimeProcesso(aux); LIS_AvancarElementoCorrente(lisProntos, 1); } }
/*********************************************************************** * $FC Função: NPE &Contar Cartas ***********************************************************************/ NPE_tpCondRet NPE_ContarCartas(NPE_Coluna coluna, int *numCartas){ LIS_tpCondRet condRet; if(coluna == NULL) return NPE_CondRetColunaNaoExiste; IrInicioLista(coluna); while(condRet != LIS_CondRetFimLista){ condRet = LIS_AvancarElementoCorrente(coluna, 1); (*numCartas)++; } return NPE_CondRetOK; }
static int* converteListaParaVetorDeInteiros(LIS_tppLista lista, int* len) { int* vet; *len = 0; if (lista == NULL || LIS_NumeroDeElementos(lista) == 0) { return NULL; } vet = (int*)calloc(LIS_NumeroDeElementos(lista) ,sizeof(int)); LIS_IrInicioLista(lista); do { vet[*len] = getInt(LIS_ObterValor(lista)); *len = (*len)+1; } while(LIS_AvancarElementoCorrente(lista, 1) == LIS_CondRetOK); return vet; }
static int EhVizinho( GRA_tppGrafo pGrafo, tpVertice * v, tpVertice * u ){ LIS_tppLista vizinhos = NULL; tpAresta * viz = NULL; int vizinho = 0; vizinhos = u->pNode->arestas; if(vizinhos == NULL) return vizinho; LIS_IrInicioLista( vizinhos ); do { viz = (tpAresta *)LIS_ObterValor(vizinhos); if(viz == NULL) break; if ( viz->pVizinho == v ) vizinho = 1 ; } while( LIS_AvancarElementoCorrente( vizinhos , 1) == LIS_CondRetOK ) ; return vizinho; }