Kimossab

Adicionar/Remover/Ver Perguntas de uma lista

Jun 8th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. void AdicionarPergunta(Pergunta *P, LPerguntas *LP)
  2. {
  3.     if(!LP)
  4.     {
  5.         printf("Lista de perguntas inexistente!\n");
  6.         return;
  7.     }
  8.  
  9.     sprintf(P->Codigo, "P%d", ++LP->Nel[4]);
  10.     if(!LP->Hash[P->Dificuldade-1])
  11.     {
  12.         LP->Hash[P->Dificuldade-1] = CNP();
  13.         LP->Hash[P->Dificuldade-1]->Info = P;
  14.     }
  15.     else
  16.     {
  17.         NPerguntas *N = CNP();
  18.         N->Info = P;
  19.         N->prox = LP->Hash[P->Dificuldade-1];
  20.         LP->Hash[P->Dificuldade-1] = N;
  21.     }
  22.     LP->Nel[P->Dificuldade-1]++;
  23. }
  24.  
  25. void RemoverPergunta(NPerguntas *P)
  26. {
  27.     if(P->Info->LRespostas)
  28.         EliminarListaRespostas(P->Info->LRespostas);
  29.  
  30.     free(P->Info->Codigo);
  31.     free(P->Info->Enunciado);
  32.     free(P->Info);
  33.     free(P);
  34. }
  35.  
  36. void VerPerguntas(LPerguntas *LP)
  37. {
  38.     if(!LP)
  39.     {
  40.         printf("Lista de perguntas inexistente!\n");
  41.         return;
  42.     }
  43.     NPerguntas *P = NULL;
  44.     for(int i = 0; i<4; i++)
  45.     {
  46.         printf("\n\nDificuldade = %d", i+1);
  47.         P = LP->Hash[i];
  48.         while(P)
  49.         {
  50.             VerPergunta(P);
  51.             P=P->prox;
  52.         }
  53.     }
  54.     /*adicionar para ver por dificuldade*/
  55. }
Advertisement
Add Comment
Please, Sign In to add comment