void Merge(Lista * dest, Lista * source1, Lista * source2) { int node; while(!listaVazia(source1)) { removeDoInicio(source1, &node); insereNoFim(dest, &node); } while(!listaVazia(source2)) { removeDoInicio(source2, &node); insereNoFim(dest, &node); } }
int removeNaPosicao(LDE *l, void *info, int pos) { if(pos < 0) return ERRO_POSICAO_INVALIDA; if(pos == 0) return removeDoInicio(l, info); EleDuplo *aux = l->cabeca; int cont = 0; while(cont < pos-1 && aux->proximo != NULL) { aux = aux->proximo; cont++; } if (cont != pos-1 || aux->proximo == NULL) return ERRO_POSICAO_INVALIDA; memcpy(info, aux->proximo->info, l->tamInfo); EleDuplo *aux2 = aux->proximo; if(aux2->proximo != NULL) aux2->proximo->anterior = aux; aux->proximo = aux2->proximo; free(aux2->info); free(aux2); return 1; //Sucesso }
/*************** REMOVE DA POSIÇÃO LÓGICA ***************/ int removeDaPosLog(pLDDE p, void *reg, unsigned int posLog) { pNoLDDE pos; unsigned int cont=0, ret = FRACASSO; if( p->lista != NULL && posLog > 0) { cont = 1; if(posLog == cont)/*PosLog == 1: inserção de um novo primeiro elemento*/ ret = removeDoInicio(p, reg); else /* posLog > 1, no minimo igual a dois */ { pos = p->lista->prox;/*pos:apontara p/ no de dados na posLog==cont*/ if (pos != NULL) { cont = 2; while(cont < posLog && pos->prox != NULL)/*1<posLog<=tam.dalista*/ { pos = pos->prox; cont++; } if (cont == posLog) /* encontrou a posLog ? */ { if(pos->prox != NULL)/*posLog eh aa do ultimo elemento ?*/ pos->prox->ant = pos->ant; pos->ant->prox = pos->prox; memcpy(reg,pos->dados,p->tamInfo); free(pos->dados); free(pos); ret = SUCESSO; } } } } return ret;/*posLog nao existe na lista*/ }
int MergeLists(Lista * dest, Lista * source1, Lista * source2) { if(dest == source1 || dest == source2) { return ERRO_MESMA_LISTA; } int node; while(!listaVazia(source1)) { removeDoInicio(source1, &node); insereNoFim(dest, &node); } while(!listaVazia(source2)) { removeDoInicio(source2, &node); insereNoFim(dest, &node); } return 1; }
int passaLista(Lista * dest, Lista * fonte) { if(dest == fonte) { return ERRO_MESMA_LISTA; } int no; while (!listaVazia(fonte)){ removeDoInicio(fonte, &no); insereNoFim(dest, &no); } return 1; }
int removeDoFim(LDE *l, void *info) { if (l->cabeca == NULL) return ERRO_LISTA_VAZIA; if(l->cabeca->proximo == NULL) return removeDoInicio(l, info); EleDuplo *aux = l->cabeca; while(aux->proximo->proximo != NULL) { aux = aux->proximo; } memcpy(info, aux->proximo->info, l->tamInfo); free(aux->proximo->info); free(aux->proximo); aux->proximo = NULL; return 1; //Sucesso }
void Correct(Lista * l, int label) { int i; while (!listaVazia(l)) { removeDoInicio(l, &i); if(codigo[i].inst == GOTO) { codigo[i].p1 = label; } else if(codigo[i].inst == IFCMP) { codigo[i].p2 = label; } else { codigo[i].label = label; } } }
void InsertIDtable(Lista *IDlist, int type) { if(listaVazia(&IDtable)) InitLista(&IDtable, sizeof(tableNode)); tableNode aux; while(removeDoInicio(IDlist, aux.id) == 1) { if(elementoExiste(IDlist, aux.id, CompareID)) { printf("<Error> in InsertIDtable(Lista *IDlist, int type)\n"); exit(0); } else { static int i = 0; aux.pos = ++i; aux.type = type; insereNoFim(&IDtable, &aux); } } }