Nerviie

LDE NUMERO NOME

May 6th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6.  
  7. typedef struct lista{
  8.     int numero;
  9.     char nome[30];
  10.     struct lista*prox,*ant;
  11. }lista;
  12.  
  13. lista *inicio,*temp,*fim;
  14.  
  15. void inseririnicio(){
  16.     int c;
  17.     do{
  18.         temp=(lista*)malloc(sizeof(lista));
  19.         printf("Numero:");
  20.         scanf("%d",&temp->numero);
  21.         printf("Nome:");
  22.         do{
  23.             gets(temp->nome);
  24.         }while(strlen(temp->nome)==0);
  25.         if(inicio==NULL){
  26.             inicio=temp;
  27.             fim=inicio;
  28.             inicio->prox=inicio->ant=NULL;
  29.         }
  30.         else{
  31.             temp->prox=inicio;
  32.             inicio->ant=temp;
  33.             temp->ant=NULL;
  34.             inicio=temp;
  35.         }
  36.         printf("Continuar?");
  37.         scanf("%d",&c);
  38.     }while(c==1);
  39.     temp=inicio;
  40.     while(temp!=NULL){
  41.         printf("\nNumero:%d\nNome:%s\n\n",temp->numero,temp->nome);
  42.         temp=temp->prox;
  43.     }
  44. }
  45.  
  46. void inserirfim(){
  47.     int c;
  48.     do{
  49.         temp=(lista*)malloc(sizeof(lista));
  50.         printf("Numero:");
  51.         scanf("%d",&temp->numero);
  52.         printf("Nome:");
  53.         do{
  54.             gets(temp->nome);
  55.         }while(strlen(temp->nome)==0);
  56.         if(inicio==NULL){
  57.             inicio=temp;
  58.             inicio->prox=inicio->ant=NULL;
  59.         }
  60.         else{
  61.             fim->prox=temp;
  62.             temp->ant=fim;
  63.             temp->prox=NULL;
  64.             fim=temp;
  65.         }
  66.         printf("Continuar?");
  67.         scanf("%d",&c);
  68.     }while(c==1);
  69.     temp=inicio;
  70.     while(temp!=NULL){
  71.         printf("\nNumero:%d\nNome:%s\n\n",temp->numero,temp->nome);
  72.         temp=temp->prox;
  73.     }
  74. }
  75.  
  76. void listarinicio(){
  77.     temp=inicio;
  78.     while(temp!=NULL){
  79.         printf("\nNumero:%d\nNome:%s\n\n",temp->numero,temp->nome);
  80.         temp=temp->prox;
  81.     }
  82. }
  83.  
  84. void listarfim(){
  85.     temp=fim;
  86.     while(temp!=NULL){
  87.         printf("\nNumero:%d\nNome:%s\n\n",temp->numero,temp->nome);
  88.         temp=temp->ant;
  89.     }
  90. }
  91.  
  92. int main() {
  93.     int op;
  94.     do{
  95.         printf("1-Inserir no início \n");
  96.         printf("2-Inserir no fim\n");
  97.         printf("3-Listar a lista inicio->fim\n");
  98.         printf("4-Listar a lista fim<-inicio \n");
  99.         printf("5-Sair\n");
  100.         printf("Tua Escolha: ");
  101.         scanf("%d",&op);
  102.         system("cls");
  103.         switch(op){
  104.             case 1: inseririnicio();
  105.                     break;
  106.             case 2: inserirfim();
  107.                     break;
  108.             case 3: listarinicio();
  109.                     break;
  110.             case 4: listarfim();
  111.                     break;
  112.             }
  113.         }while (op!=5);
  114.     system("cls");
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment