#include <stdio.h>
#include <stdlib.h>
//Estrutura principal da lista.
struct listaE
{
int vl;
struct listaE *pl;
};
//funcoes da lista:
void displayLL(struct listaE *p)
{
printf("Mostrar Lista:\n");
if(p)
{
do
{
printf(" %d", p->vl);
p=p->pl;
}
while(p);
}
else
printf("Lista Vazia.");
}
//Q 1
int comprimento (struct listaE *p)
{
printf("\n");
int i=0;
if(p)
{
do
{
p=p->pl;
i++;
}
while(p);
printf(" %d",i);
}
else
printf("Lista vazia.");
}
//Q 2
int maiores(struct listaE *p)
{
int x=48;
int i=5;
printf("\n");
printf("Valor(es) maior(es) que o de X:");
printf("\n");
if(p)
{
do
{
p=p->pl;
i--;
}
while(x > p->vl);
printf(" %d",i);
}
else
printf("Lista vazia.");
}
// Q 3
int ultimo (struct listaE *p)
{
printf("\n");
printf("O ultimo valor inteiro e:\n");
if(p)
{
do
{
p=p->pl;
}
while(p && p->pl != NULL );
printf(" %d", p->vl);
}
else
printf("Lista vazia.");
}
int main(void)
{
struct listaE *Lista1 = NULL;
struct listaE *Lista2 = NULL;
struct listaE *Lista3 = NULL;
struct listaE *Lista4 = NULL;
struct listaE *Lista5 = NULL;
//Criando os nos e associando os dados.
Lista1 = (struct listaE*) malloc(sizeof(struct listaE*));
Lista1->vl = 18;
Lista2 = (struct listaE*) malloc(sizeof(struct listaE*));
Lista2->vl = 27;
Lista3 = (struct listaE*) malloc(sizeof(struct listaE*));
Lista3->vl = 33;
Lista4 = (struct listaE*) malloc(sizeof(struct listaE*));
Lista4->vl = 45;
Lista5 = (struct listaE*) malloc(sizeof(struct listaE*));
Lista5->vl = 57;
//Conectando os nos
Lista1->pl = Lista2;
Lista2->pl = Lista3;
Lista3->pl = Lista4;
Lista4->pl = Lista5;
Lista5->pl = NULL;
//Mostrando a lista.
if(Lista1)
displayLL(Lista1);
comprimento(Lista1);
maiores(Lista1);
ultimo(Lista1);
return 0;
}