Posted By

makozic on 12/02/11


Tagged

implementacija


Versions (?)

red_polje z3


 / Published in: C++
 

Implementacija pomoću polja

  1. struct tord{
  2. int i[1000];
  3. int j[1000];
  4. int p;
  5. int z;
  6. };
  7.  
  8. struct tred{
  9. int i;
  10. int j;
  11. };
  12.  
  13. typedef tord red;
  14. typedef tred element;
  15.  
  16. tord *InitQ(tord *&Q){
  17. Q = new tord;
  18. Q->p = 0;
  19. Q->z = 999;
  20. return Q;
  21. };
  22.  
  23. int AddOne(int x){
  24. return ((x+1)%(1000));
  25. };
  26.  
  27. element FrontQ(tord *Q){
  28. element elem;
  29. elem.i = elem.j = -1;
  30. if(AddOne(Q->z) != Q->p){
  31. elem.i = Q->i[Q->p];
  32. elem.j = Q->j[Q->p];
  33. }
  34. return elem;
  35. };
  36.  
  37. void EnQueueQ(element x,tord *Q){
  38. if(AddOne(AddOne(Q->z)) != Q->p){
  39. Q->z = AddOne(Q->z);
  40. Q->i[Q->z] = x.i;
  41. Q->j[Q->z] = x.j;
  42. }
  43. };
  44.  
  45. void DeQueueQ(tord *Q){
  46. if(AddOne(Q->z) != Q->p) Q->p = AddOne(Q->p);
  47. };
  48.  
  49. bool IsEmptyQ(tord *Q){
  50. if(AddOne(Q->z) != Q->p) return false;
  51. else return true;
  52. };

Report this snippet  

You need to login to post a comment.