remoção em lista simplesmente encadeada

Post on 22-Jan-2018

186 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

LISTA SIMPLESMENTE ENCADEADA – REMOÇÃO

Prof.ª M.ª Elaine Cecília Gatto

REMOVER DO INICIO

REMOVER DO INICIO

node *retiraInicio(node *LISTA)

{

if (LISTA->prox == NULL) {

printf("Lista ja esta vazia\n");

return NULL;

} else {

node *aux = LISTA->prox;

LISTA->prox = aux->prox;

tam--;

return tmp;

}

}

REMOVER DO INICIO

if (LISTA->prox == NULL) {

printf("Lista esta vazia\n");

return NULL;

NULLNULL

PRÓXIMO

LISTA (0X10)

REMOVER DO INICIO

node *aux = LISTA->prox;

LISTA->prox = aux->prox;

tam--;

return tmp;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

REMOVER DO INICIO

node *aux = LISTA->prox;

LISTA->prox = aux->prox;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

0XA

PRÓXIMO

AUX

REMOVER DO INICIO

node *aux = LISTA->prox;

LISTA->prox = aux->prox;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

0XA

PRÓXIMO

AUX

REMOVER DO INICIO

node *aux = LISTA->prox;

LISTA->prox = aux->prox;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

AUX

REMOVER DO INICIO

node *aux = LISTA->prox;

LISTA->prox = aux->prox;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

AUX

REMOVER DO INICIO

node *aux = LISTA->prox;

LISTA->prox = aux->prox;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

AUX

REMOVER DO INICIO

node *aux = LISTA->prox;

LISTA->prox = aux->prox;

x 0XB1

PRÓXIMO

LISTA 0XB1

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

AUX

REMOVER DO INICIO

node *aux = LISTA->prox;

LISTA->prox = aux->prox;

LISTA 0XB1

PRÓXIMO

0XA

NULLk NULL

PRÓXIMO

0XB1

REMOVER DO FIM

REMOVER DO FIM

node *retiraFim(node *LISTA) {

if(LISTA->prox == NULL){

printf("Lista ja vazia\n\n");

return NULL;

} else {

node *ultimo = LISTA->prox, *penultimo = LISTA;

while(ultimo->prox != NULL){

penultimo = ultimo;

ultimo = ultimo->prox;

}

penultimo->prox = NULL;

tam--;

return ultimo;

}

}

REMOVER DO FIM

if(LISTA->prox == NULL){

printf("Lista ja vazia\n\n");

return NULL;

NULLNULL

PRÓXIMO

LISTA (0X10)

REMOVER DO FIM

{ node *ultimo = LISTA->prox, *penultimo = LISTA;

while(ultimo->prox != NULL){

penultimo = ultimo;

ultimo = ultimo->prox;

} penultimo->prox = NULL;

tam--;

return ultimo;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

REMOVER DO FIMnode *ultimo = LISTA->prox, *penultimo = LISTA;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

PRÓXIMO

Ultimo

REMOVER DO FIMnode *ultimo = LISTA->prox, *penultimo = LISTA;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

PRÓXIMO

Ultimo

REMOVER DO FIMnode *ultimo = LISTA->prox, *penultimo = LISTA;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

ULTIMO

REMOVER DO FIMnode *ultimo = LISTA->prox, *penultimo = LISTA;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

PRÓXIMO

Penúltimo

ULTIMO

REMOVER DO FIMnode *ultimo = LISTA->prox, *penultimo = LISTA;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

ULTIMOPENULTIMO

ULTIMOPENULTIMO

REMOVER DO FIMwhile(ultimo->prox != NULL) { penultimo = ultimo; ultimo = ultimo->prox; }

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

Ultimo -> prox != null0XB1 != NULL

F

ULTIMOPENULTIMO

REMOVER DO FIMwhile(ultimo->prox != NULL) { penultimo = ultimo; ultimo = ultimo->prox; }

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

ULTIMOPENULTIMO

REMOVER DO FIMwhile(ultimo->prox != NULL) { penultimo = ultimo; ultimo = ultimo->prox; }

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

ULTIMOPENULTIMO

REMOVER DO FIMwhile(ultimo->prox != NULL) { penultimo = ultimo; ultimo = ultimo->prox; }

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

ULTIMOPENULTIMO

REMOVER DO FIMwhile(ultimo->prox != NULL) { penultimo = ultimo; ultimo = ultimo->prox; }

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

ULTIMOPENULTIMO

REMOVER DO FIMwhile(ultimo->prox != NULL) { penultimo = ultimo; ultimo = ultimo->prox; }

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

Ultimo -> prox != nullNULL != NULL

V

ULTIMOPENULTIMO

REMOVER DO FIMpenultimo->prox = NULL;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

ULTIMOPENULTIMO

REMOVER DO FIMpenultimo->prox = NULL;

x 0XB1

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULLk NULL

PRÓXIMO

0XB1

PENULTIMO

REMOVER DO FIMpenultimo->prox = NULL;

x NULL

PRÓXIMO

LISTA 0X15

PRÓXIMO

0X150XA

NULL

top related