Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define MAX 50 //TAMANHO DO VETOR DE 50 POSIÇÕES
- typedef struct { // STRUCT PARA A INSERÇÃO DE DADOS NA LISTA
- char nome[MAX]; // NOME DO TIPO (CHAR) DE 50 CARACTÉRES // [MAX] IGUAL A DEFINIÇÃO DE TAMNHO 50
- int idade, id; // IDADE / ID AUTO_INCREMENT (INT)
- }usuario; // APELIDO "usuario" PARA A STRUCT PESSOA
- typedef struct NODO{ //CRIAÇÃO DE PONTEIROS PARA APONTAR OS NÓS DA LISTA DUPLAMENTE ENCADEADA
- usuario *dados; //DADOS DO ELEMENTO QUE SERÁ CADASTRADO NO NÓ
- struct NODO *proximo; //Próximo elemento do NÓ
- struct NODO *anterior; // Elemento anterior do NÓ
- };
- typedef struct{ //CRIAÇÃO DA STRUCT PARA APONTAR O INÍCIO DE UM NOVO ELEMENTO
- struct NODO *inicio //Ponteiro apontando para a nova alocação do nó
- }List; //apelido "List" para a lista duplamente encadeada em conjunto com a *NODO*
- void init(List *L){ //INICIAÇÃO DA LISTA
- L->inicio = NULL; //SE O INÍCIO DA LISTA ESTIVER NULL ENTAÕ INICIAMOS A LISTA
- }
- int empty(List *L) { //CHECAR SE A LISTA ESTÁ VAZIA
- if (L->inicio == NULL) // SE O INÍCIO DA LISTA ESTIVER = "NULL" a lista está vazia.
- return 1; //LISTA VAZIA
- else // CASO A CONDIÇÃO SEJA FALSA EXISTE ELEMENTO NA LISTA
- return 0; //LISTA COM ELEMENTOS
- }
- void insert(List *L, usuario *p){//ponteiro *L = struct lista, ponteiro *p = struct usuario;
- struct NODO *no = (struct NODO*) malloc(sizeof(struct NODO));
- if(L->inicio == NULL){
- L->inicio->anterior = no;
- }
- no->dados = p;
- no->proximo = L->inicio;
- no->anterior = NULL;
- L->inicio = no;
- }
- void imprimir(List *L){
- struct NODO *imprimi = L->inicio;
- while(imprimi!=NULL){
- printf("ID: %d | NOME: %c | IDADE: %d\n",imprimi->dados->id,imprimi->dados->nome,imprimi->dados->idade);
- imprimi=imprimi->proximo;
- }
- }
- main(){
- int ctrl,c=0;
- struct List *L;
- struct NODO *guardar;
- guardar->dados;
- usuario p;
- do{
- system("CLS");
- printf(
- "Selecione opcao que deseja, veja nosso menu:|\n"
- "---------------------------------------------\n"
- "1 - Criar Lista |\n"
- "2 - Mostrar Lista |\n"
- "3 - Inserir Usuario |\n"
- "4 - Deletar Usuario |\n"
- "5 - Ordenar Idades |\n"
- "---------------------\n"
- "0 - SAIR DO PROGRAMA.|\n"
- "---------------------\n"
- );
- scanf("%d", &ctrl);
- switch (ctrl)
- {
- case 0:
- printf("Fim da Lista");
- getch();
- break;
- case 1:
- system("CLS");
- init(&L);
- printf(" \n\nLISTA CRIADA\n\n Pressione uma tecla para voltar ao menu.");
- getch();
- break;
- case 3:
- c++;
- insert(&guardar,&p);
- break;
- }
- }while(ctrl != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement