Posted By


nhorvat on 12/03/11

Tagged


Statistics


Viewed 84 times
Favorited by 0 user(s)

red_pokazivac.h


/ Published in: C++
Save to your folder(s)

simulacija cekaone


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.