Posted By

kdomic on 12/03/11


Tagged

c++


Versions (?)

red_polje.h


 / Published in: C++
 

Simulacija reda u liječničkoj ordinaciji - red_polje.h

  1. struct tdata{
  2. int x,y, prioritet, rb;
  3. };
  4.  
  5. struct tlist{
  6. tdata data[10000];
  7. int front, rear;
  8. };
  9.  
  10. int AddOne(int n){
  11. return (( n + 1 ) % 10000);
  12. }
  13.  
  14. bool IsEmptyQ(tlist *Q){
  15. if(AddOne(Q->rear)==Q->front)
  16. return true;
  17. return false;
  18. }
  19.  
  20. tdata FronQ(tlist *Q){
  21. tdata data;
  22. data.x = 0; data.y = 0;
  23. if(IsEmptyQ(Q))
  24. return data;
  25. return Q->data[Q->front];
  26. }
  27.  
  28. void EnQueueQ(tdata x,tlist *Q){
  29. Q->rear = AddOne(Q->rear);
  30. Q->data[Q->rear] = x;
  31. }
  32.  
  33. bool DeQueueQ(tlist *Q){
  34. if(IsEmptyQ(Q))
  35. return false;
  36. Q->front = AddOne(Q->front);
  37. return true;
  38. }
  39.  
  40. tlist* InitQ(tlist *Q){
  41. Q = new tlist;
  42. Q->front = 0;
  43. Q->rear = 9999;
  44. return Q;
  45. }

Report this snippet  

You need to login to post a comment.