Posted By

mikoscak on 12/19/11


Tagged


Versions (?)

pokazivac


 / Published in: C++
 

implementacija reda pomocu pokazivaca

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

Report this snippet  

You need to login to post a comment.