Guest User

Untitled

a guest
Jan 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. //Alan Cordeiro
  6. //Listas encadeadas
  7.  
  8. struct eficiencia {
  9.        int segundos;
  10.        struct eficiencia *prox;
  11. };
  12.  
  13.  
  14. void imprime (struct eficiencia *cabeca){
  15.    printf("Segundos gastos por operarios\n");
  16.    struct eficiencia *aux;
  17.    aux = cabeca;
  18.    
  19.    while(aux->prox != NULL) {
  20.         aux = aux->prox;
  21.         printf("%d\n",aux->segundos);  
  22.    }
  23.    
  24. }
  25.  
  26.  
  27.  
  28. void addOperario(struct eficiencia *cabeca) {
  29.    struct eficiencia *novo;
  30.    int segundos;
  31.  
  32.    novo = (struct eficiencia *) malloc(sizeof(cabeca));
  33.    
  34.    printf("Insira o tempo gasto pelo operario\n");
  35.    scanf("%d",&segundos);
  36.                      
  37.    novo->segundos = segundos;
  38.    novo->prox = cabeca->prox;
  39.    cabeca->prox = novo;
  40.  
  41. }
  42.  
  43.  
  44. int main () {
  45.     int operarios;
  46.    
  47.     printf("Insira a quantidade de operarios\n");
  48.     scanf("%d",&operarios);
  49.    
  50.     struct eficiencia grupo;
  51.     grupo.prox = NULL;
  52.    
  53.     for(int x=0; x < operarios; x++)
  54.             addOperario(&grupo);
  55.     imprime(&grupo);
  56.     system("pause");
  57. }
Add Comment
Please, Sign In to add comment