Skip to content
Snippets Groups Projects
Commit 2ceb5fdd authored by Leonardo Krambeck's avatar Leonardo Krambeck
Browse files

arruma remove inicio e implementa remove fim

parent 07c3a1fb
No related branches found
No related tags found
No related merge requests found
......@@ -132,10 +132,6 @@ int insere_ordenado_lista(int item, t_lista *l)
return 1;
}
/*
Remove o primeiro elemento da lista e o retorna em *item.
Retorna 1 se a operação foi bem sucedida e zero caso contrário.
*/
int remove_inicio_lista(int *item, t_lista *l)
{
if (lista_vazia(l))
......@@ -144,10 +140,11 @@ int remove_inicio_lista(int *item, t_lista *l)
return 0;
}
t_nodo *p = l->ini;
t_nodo *p = l->ini->prox;
l->ini = p->prox;
p->prox->prev = l->ini;
p->prev->prox = p->prox;
p->prox->prev = p->prev;
*item = p->chave;
free (p);
......@@ -156,11 +153,26 @@ int remove_inicio_lista(int *item, t_lista *l)
return 1;
}
/*
Remove o último elemento da lista e o retorna em *item.
Retorna 1 se a operação foi bem sucedida e zero caso contrário.
*/
int remove_fim_lista(int *item, t_lista *l){return 1;}
int remove_fim_lista(int *item, t_lista *l)
{
if (lista_vazia(l))
{
item = NULL;
return 0;
}
t_nodo *p = l->fim->prev;
p->prev->prox = p->prox;
p->prox->prev = p->prev;
*item = p->chave;
free (p);
l->tamanho--;
return 1;
}
/*
Se o elemento chave existir na lista, o retorna em *item.
......
......@@ -3,6 +3,8 @@
#include "lib_lista.h"
void imprime (t_lista *l)
{
if (!lista_vazia(l))
{
t_nodo *p = l->ini->prox;
......@@ -13,6 +15,7 @@ void imprime (t_lista *l)
}
printf ("%d\n",p->chave);
}
}
int main ()
{
......@@ -26,7 +29,8 @@ int main ()
insere_ordenado_lista(3, &l);
insere_ordenado_lista(2, &l);
imprime (&l);
remove_inicio_lista(&item, &l);
remove_fim_lista(&item, &l);
remove_fim_lista(&item, &l);
imprime (&l);
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment