int elementoExiste(Lista *l, void *info, int (*compara_info)(void *, void *)) { Elemento *aux = l->cabeca; if (aux == NULL) return 0; while(aux != NULL) { if (compara_info(aux->info, info) == 0) { return 1; } aux = aux->proximo; } return 0; }
int buscaElemento(Lista *l, void *info, int (*compara_info)(void *, void *)) { Elemento *aux = l->cabeca; if (aux == NULL) return ERRO_ELEMENTO_NAO_ENCONTRADO; while (aux != NULL) { if (compara_info(info, aux->info) == 0) { memcpy(info, aux->info, l->tamInfo); return 1; // Sucesso } aux = aux->proximo; } return ERRO_ELEMENTO_NAO_ENCONTRADO; }
int inserir(Fila *f, void *info, float (*compara_info)(void*,void*)) { if(fila_cheia(*f)) return ERRO_FILA_CHEIA; int atual = f->fim; int anterior = ant(atual, f->capacidade); int cont = 0; while (cont < f->num_ele && compara_info(f->dados[anterior],info)) { f->dados[atual] = f->dados[anterior]; atual = anterior; anterior = ant(atual, f->capacidade); cont++; } f->dados[atual] = malloc (f->tamInfo); memcpy(f->dados[atual], info, f->tamInfo); f->fim++; f->num_ele++; if (f->fim == f->capacidade) f->fim = 0; return 0; }