Posted By

mladenberakovic on 12/03/11


Tagged


Versions (?)

red_pokazivac.h


 / Published in: C++
 

Zadatak 3 - Strukture Podataka

  1. #include <iostream>
  2. using namespace std;
  3. struct struktura{
  4. int x, y;
  5. struktura *slijedeci;
  6. };
  7. struct strukturaP{
  8. struktura *front,*rear;
  9. };
  10. typedef strukturaP queue;
  11. typedef struktura atrib;
  12.  
  13. queue *InitQ(queue *&Q){
  14. Q=new queue;
  15. atrib *novi=new atrib;
  16. Q->front=novi;
  17. Q->rear=novi;
  18. novi->slijedeci=NULL;
  19. return Q;
  20. };
  21.  
  22. atrib FrontQ(queue *Q){
  23. atrib pom;
  24. pom.x=pom.y=-1;
  25. if(Q->rear != Q->front){
  26. pom.x=Q->front->slijedeci->x;
  27. pom.y=Q->front->slijedeci->y;
  28. }
  29. return pom;
  30. };
  31.  
  32. void EnQueueQ(atrib x, queue *Q){
  33. atrib *novi=new atrib;
  34. novi->x=x.x;
  35. novi->y=x.y;
  36. novi->slijedeci=NULL;
  37. Q->rear->slijedeci=novi;
  38. Q->rear=novi;
  39. };
  40.  
  41. void DeQueueQ(queue *Q){
  42. if(Q->rear != Q->front){
  43. atrib *pom=Q->front;
  44. Q->front=Q->front->slijedeci;
  45. delete pom;
  46. }
  47. else
  48. cout<<"Prazan red!"<<endl;
  49. };
  50.  
  51. bool IsEmptyQ(queue *Q){
  52. if(Q->rear != Q->front)
  53. return false;
  54. return true;
  55. };

Report this snippet  

You need to login to post a comment.