Posted By


mdzeko on 12/03/11

Tagged


Statistics


Viewed 390 times
Favorited by 0 user(s)

red_pokazivac.h


/ Published in: C++
Save to your folder(s)

naknadno dodana biblioteka zaglavlja red_pokazivac.h


Copy this code and paste it in your HTML
  1. #include<iostream>
  2. struct tpacijent
  3. {
  4. int cek, traj, prioritet, redni;
  5. tpacijent *next;
  6. };
  7.  
  8. struct tred
  9. {
  10. tpacijent *front;
  11. tpacijent *rear;
  12. };
  13.  
  14. /////////////////////////////////////
  15.  
  16. tred* InitQ(tred *q)
  17. {
  18. q = new tred;
  19. q->front = new tpacijent;
  20. q->front->next = NULL;
  21. q->rear = q->front;
  22. return q;
  23. }
  24.  
  25. /////////////////////////////////////
  26.  
  27. bool IsEmptyQ(tred *q)
  28. {
  29. if(q->front==q->rear)
  30. return 1;
  31. return 0;
  32. }
  33.  
  34. /////////////////////////////////////
  35.  
  36. tpacijent FronQ(tred *q)
  37. {
  38. if(!IsEmptyQ(q))
  39. return *q->front->next;
  40. }
  41.  
  42. /////////////////////////////////////
  43.  
  44. void EnQueueQ(tpacijent x, tred *q)
  45. {
  46. tpacijent *novi = new tpacijent;
  47. memcpy(novi,&x,sizeof(tpacijent));
  48. novi->next = NULL;
  49. if(IsEmptyQ(q))
  50. {
  51. q->front->next = novi;
  52. q->rear = novi;
  53. }
  54. else
  55. {
  56. q->rear->next = novi;
  57. q->rear = novi;
  58. }
  59. }
  60.  
  61. /////////////////////////////////////
  62.  
  63. bool DeQueueQ(tred *q)
  64. {
  65. if(IsEmptyQ(q))
  66. return false;
  67. tpacijent *first = q->front->next;
  68. if(first->next)
  69. q->front->next = first->next;
  70. else
  71. q->front = q->rear;
  72. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.