Guest User

Untitled

a guest
Aug 19th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Aluno{
  5.     int matricula;
  6.     struct Aluno * prox;
  7. };
  8.  
  9. struct Aluno * novo, * lista, * ultimo, *elemento;
  10. void primeiro(int mat)
  11.  
  12. {
  13.     lista = malloc(sizeof(struct Aluno));
  14.     lista -> matricula = mat;
  15. }
  16.  
  17. void demais(int mat){
  18.     novo = malloc(sizeof(struct Aluno));
  19.     novo -> matricula = mat;
  20.     ultimo = lista;
  21.     while (ultimo -> prox != NULL){
  22.         ultimo = ultimo -> prox;
  23.     }
  24.     ultimo -> prox = novo;
  25. }
  26.  
  27. void listar(){
  28.     printf("\n\nListando\n");
  29.     ultimo = lista;
  30.     while(ultimo != NULL){
  31.         printf("%d\n", ultimo -> matricula);
  32.         ultimo = ultimo -> prox;
  33.     }
  34. }
  35.  
  36.  
  37. int main(int argc, char** argv) {
  38.     int mat;
  39.     while(1){
  40.         scanf("%d", &mat);
  41.         if (mat == 0){
  42.             break;
  43.         }
  44.  
  45.         if (lista == NULL){
  46.             primeiro(mat);
  47.         } else{
  48.             demais(mat);
  49.         }
  50.     }
  51.  
  52.     listar();
  53.  
  54.     return (EXIT_SUCCESS);
  55. }
Add Comment
Please, Sign In to add comment