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

implementa tamanho e insere fim

parent f43f8c2d
No related branches found
No related tags found
No related merge requests found
...@@ -60,10 +60,6 @@ void destroi_lista(t_lista *l) ...@@ -60,10 +60,6 @@ void destroi_lista(t_lista *l)
l->tamanho = 0; l->tamanho = 0;
} }
/*
Insere o elemento item no início da lista.
Retorna 1 se a operação foi bem sucedida e zero caso contrário.
*/
int insere_inicio_lista(int item, t_lista *l) int insere_inicio_lista(int item, t_lista *l)
{ {
t_nodo *new; t_nodo *new;
...@@ -73,9 +69,8 @@ int insere_inicio_lista(int item, t_lista *l) ...@@ -73,9 +69,8 @@ int insere_inicio_lista(int item, t_lista *l)
return 0; return 0;
new->chave = item; new->chave = item;
new->prox = l->ini->prox;
new->prev = l->ini; new->prev = l->ini;
new->prox = l->ini->prox;
l->ini->prox->prev = new; l->ini->prox->prev = new;
l->ini->prox = new; l->ini->prox = new;
...@@ -85,17 +80,34 @@ int insere_inicio_lista(int item, t_lista *l) ...@@ -85,17 +80,34 @@ int insere_inicio_lista(int item, t_lista *l)
return 1; return 1;
} }
/* int tamanho_lista(int *tam, t_lista *l)
Retorna o tamanho da lista em *tam. {
Retorna 1 se a operação foi bem sucedida e zero caso contrário. if (l->ini == NULL && l->fim == NULL)
*/ return 0;
int tamanho_lista(int *tam, t_lista *l){return 1;}
/* *tam = l->tamanho;
Insere o elemento item no final da lista. return 1;
Retorna 1 se a operação foi bem sucedida e zero caso contrário. }
*/
int insere_fim_lista(int item, t_lista *l){return 1;} int insere_fim_lista(int item, t_lista *l)
{
t_nodo *new;
new = (t_nodo*) malloc (sizeof (t_nodo));
if (new == NULL)
return 0;
new->chave = item;
new->prox = l->fim;
new->prev = l->fim->prev;
l->fim->prev->prox = new;
l->fim->prev = new;
l->tamanho++;
return 1;
}
/* /*
Insere o elemento item na lista de maneira que ela fique em ordem Insere o elemento item na lista de maneira que ela fique em ordem
......
...@@ -5,10 +5,16 @@ ...@@ -5,10 +5,16 @@
int main () int main ()
{ {
t_lista l; t_lista l;
int tam;
inicializa_lista(&l); inicializa_lista(&l);
insere_inicio_lista (10, &l); insere_inicio_lista (10, &l);
if (!lista_vazia(&l)) printf("nao vazia\n"); insere_inicio_lista (5, &l);
tamanho_lista(&tam, &l);
printf ("tam: %d\n",tam);
insere_fim_lista (8, &l);
tamanho_lista(&tam, &l);
printf ("tam: %d\n",tam);
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment