Posted By

mikoscak on 12/19/11


Tagged


Versions (?)

polje


 / Published in: C++
 

implementacija reda pomocu polja

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

Report this snippet  

You need to login to post a comment.