Lista Cadastral
Lista Cadastral
Lista Cadastral
Departamento de Computação
Autor
792238
Ciência da Computação
/*
NOME: PIETRO MINGHINI MORALLES
RA: 792238
DISCIPLINA: Algoritmos e Estruturas de Dados 1
EXERCICIO: F5 – LISTA CADASTRAL COM ALOCAÇÃO ENCADEADA E
DINÂMICA.
DESCRIÇÃO: DECLARAÇÃO DO TAD LISTA COM ALOCAÇÃO ENCADEADA E
DINÂMICA.
*/
#ifndef LISTA_CADASTRAL_ORDENADA_LISTA_CADASTRAL_TAD_H
#define LISTA_CADASTRAL_ORDENADA_LISTA_CADASTRAL_TAD_H
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
struct Node{
int info;
struct Node *next;
};
#endif //LISTA_CADASTRAL_ORDENADA_LISTA_CADASTRAL_TAD_H
/*
NOME: PIETRO MINGHINI MORALLES
RA: 792238
DISCIPLINA: Algoritmos e Estruturas de Dados 1
EXERCICIO: F5 – LISTA CADASTRAL COM ALOCAÇÃO ENCADEADA E
DINÂMICA.
DESCRIÇÃO: IMPLEMENTAÇÃO DAS FUNÇÕES TAD LISTA COM ALOCAÇÃO
ENCADEADA E DINÂMICA
*/
#include "Lista_Cadastral_TAD.h"
if(vazia(lista)){
return false;
}
else{
Laux = lista->inicio;
while(Laux != NULL){
if(Laux->info == *x){
return true;
}
else{
Laux = Laux->next;
}
}
return false;
}
};
/*
NOME: PIETRO MINGHINI MORALLES
RA: 792238
DISCIPLINA: Algoritmos e Estruturas de Dados 1
EXERCICIO: F5 – LISTA CADASTRAL COM ALOCAÇÃO ENCADEADA E
DINÂMICA.
DESCRIÇÃO: ATIVIDADE PARA IMPLEMENTAR E TESTAR O TAD LISTA COM
ALOCAÇÃO ENCADEADA E DINAMICA
*/
#include "Lista_Cadastral_TAD.h"
void imprimeLista(Lista *lista);
void MaiorElem(Lista *lista, bool *deuCerto, int *x);
int main() {
int op = 10, valor;
bool resultado;
Lista lista1;
cria(&lista1);
while(op != 0){
printf("--- MENU ---: (1) Verifica vazia -- (2) Verifica
cheia -- (3) Insere elemento -- (4) Remove elemento -- (5)
Imprime\n -- (6) Maior elemento --\n");
scanf("%d", &op);
if(op == 1){
if(vazia(&lista1)){
printf("Lista vazia.\n");
}
else{
printf("Lista n vazia.\n");
}
}
else if(op == 2){
if(cheia(&lista1)){
printf("Lista cheia.\n");
}
else{
printf("Lista n cheia\n");
}
}
else if(op == 3){
printf("Digite o elemento a ser inserido na lista: ");
scanf("%d", &valor);
insere(&lista1, valor, &resultado);
if(resultado){
printf("Elemento %d inserido na lista.\n", valor);
}
else{
printf("Elemento %d n inserido na lista.\n",
valor);
}
}
else if(op == 4){
printf("Digite o elemento a ser removido da lista: ");
scanf("%d", &valor);
retira(&lista1, &valor, &resultado);
if(resultado){
printf("Elemento %d removido da lista.\n", valor);
}
else{
printf("Elemento %d nao encontrado ou lista
vazia.\n", valor);
}
}
else if(op == 5){
imprimeLista(&lista1);
}
else if(op == 6){
MaiorElem(&lista1, &resultado, &valor);
if(resultado){
printf("O maior elemento da lista eh %d.\n",
valor);
}
else{
printf("Lista vazia.\n");
}
}
}
return 0;
}
void imprimeLista(Lista *lista){
NodePtr Laux;
Laux = (NodePtr) malloc(sizeof(NodePtr));
Laux = lista->inicio;
if(vazia(lista)){
printf("Lista vazia.\n");
}
else{
while(Laux != NULL){
printf("%d ", Laux->info);
Laux = Laux->next;
}
printf("\n");
}
}
void MaiorElem(Lista *lista, bool *deuCerto, int *x){
int maior = -50000;
NodePtr Laux;
Laux = (NodePtr) malloc(sizeof(NodePtr));
Laux = lista->inicio;
if(vazia(lista)){
*deuCerto = false;
}
else{
while(Laux != NULL){
if(Laux->info >= maior){
maior = Laux->info;
}
Laux = Laux->next;
}
*x = maior;
*deuCerto = true;
}
}