bella
Uploaded by
10 SLIDES
352 VUES
110LIKES

exercícios listas encadeadas

DESCRIPTION

exercícios listas encadeadas.

1 / 10

Télécharger la présentation

exercícios listas encadeadas

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript

Playing audio...

  1. exercícioslistasencadeadas

  2. Considerando listas de valores inteiros, implemente uma função que receba como parâmetro uma lista encadeada e um valor inteiro n e divida a lista em duas, de tal forma que a segunda lista comece no primeiro nó logo após a primeira ocorrência de n na lista original. A figura a seguir ilustra essa separação: Essa função deve obedecer ao protótipo: Lista separa (Lista l, int n); A função deve retornar um ponteiro para a segunda sub-divisão da lista original, enquanto l deve continuar apontando para o primeiro elemento da primeira subdivisão dalista.

  3. /* funçãosepara */ Lista separa (Lista l, int n) { Lista p; /* variável auxiliar para percorrer a lista */ Lista q; /* variável auxiliar para nova lista */ for (p = l; p != NULL ; p = p->elo) if (p->info == n) { q = p->elo; p->elo= NULL; return q; } return NULL; }

  4. Listaconstroi (int n, int *v);

  5. Lista constroi (int n, int* v) { Lista p; /* variável auxiliar para percorrer a lista */ Lista q; /* variável auxiliar para criar a nova lista */ inti; q = NULL; for(i=n-1; i>=0; i--) { p = (Lista) malloc(sizeof(struct no)); p->elo= q; p->info = v[i]; q = p; } return q; }

  6. Listaretira_prefixo(int n, Lista L);

  7. Lista retira_prefixo (Lista l, int n) { Lista p; /* variável auxiliar para percorrer a lista */ Listaq; /* variávelauxiliar */ int m = 1; p = l; while(p != NULL && m <= n) { m = m+1; q = p->elo; free(p); p = q; } return p; }

  8. Listains_ordenado (Lista l, int mat, char *nome, float nota);

  9. structdados{ intmatricula; char nome[81]; float media; struct dados* prox; } typedefstructdados *Lista;

  10. Lista ins_ordenado(Lista L, intmat, char* nome, float nota) { Listap = L; Listaant = NULL; Listanovo = (Lista)malloc(sizeof(struct dados); novo ->mat = mat; strcpy(novo->nome, nome); novo->media = nota; novo->prox = NULL; If (p==NULL) return novo; while ((p!=NULL) && (novo->mat > p->mat)) { ant = p; p = p->prox;} if (ant == NULL) {novo->prox = p; return novo;} novo ->prox = ant->prox; ant->prox = novo; return L; }

More Related