Posted By

dapatafta on 11/20/10


Tagged


Versions (?)

red_polje.h


 / Published in: C++
 

  1. struct klijent
  2. {
  3. char ime[20];
  4. char prezime[20];
  5. int godina;
  6. float stanje;
  7. int transakcija;
  8. };
  9.  
  10. struct tred
  11. {
  12. klijent elementi[10000];
  13. int front, rear;
  14. };
  15.  
  16. typedef struct tred *pred;
  17.  
  18. int AddOne(int n)
  19. {
  20. return (n + 1) % 10000;
  21. }
  22.  
  23. klijent FrontQ(tred *Q)
  24. {
  25. if (AddOne(Q->rear) == Q->front)
  26. {
  27. klijent x;
  28. x.godina = 0;
  29. x.stanje = 0;
  30. x.transakcija = 0;
  31.  
  32. return x;
  33. }
  34. else
  35. return Q->elementi[Q->front];
  36. }
  37.  
  38. void EnQueueQ(klijent x, tred *Q)
  39. {
  40. if (AddOne(AddOne(Q->rear)) != Q->front)
  41. {
  42. Q->rear = AddOne(Q->rear);
  43. Q->elementi[Q->rear] = x;
  44. }
  45. }
  46.  
  47. void DeQueueQ(tred *Q)
  48. {
  49. if (AddOne(Q->rear) != Q->front) Q->front = AddOne(Q->front);
  50. }
  51.  
  52. void InitQ(tred *Q)
  53. {
  54. Q->rear = 9999;
  55. Q->front = 0;
  56. }
  57.  
  58. bool IsEmptyQ(tred *Q)
  59. {
  60. if (AddOne(Q->rear) == Q->front)
  61. return true;
  62. else
  63. return false;
  64. }

Report this snippet  

You need to login to post a comment.