Posted By

dekisanta on 11/22/10


Tagged

red Queue


Versions (?)

red_pokazivac.h


 / Published in: C++
 

URL: dekisanta_Z3_3

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct tlista{
  5. tdata element;
  6. tlista *next;
  7. };
  8.  
  9. struct tred{
  10. tlista *front, *rear;
  11. };
  12.  
  13. void InitQ(tred *Q){
  14. tlista *glava = new tlista;
  15. glava->next = NULL;
  16. Q->front = glava;
  17. Q->rear = glava;
  18. }
  19.  
  20. bool IsEmptyQ(tred *Q){
  21. if(Q->front == Q->rear) return 1;
  22. else return 0;
  23. }
  24.  
  25. tdata FrontQ(tred *Q){
  26. if(IsEmptyQ(Q)) cout << "Red je prazan." << endl;
  27. else return Q->front->next->element;
  28. }
  29.  
  30. void EnQueueQ(tdata X, tred *Q){
  31. tlista *novi = new tlista;
  32. novi->element = X;
  33. novi->next = NULL;
  34. Q->rear->next = novi;
  35. Q->rear = novi;
  36. }
  37.  
  38. void DeQueueQ(tred *Q){
  39. if(IsEmptyQ(Q)) cout << "Red je prazan." << endl;
  40. else{
  41. tlista *brisani;
  42. brisani = Q->front;
  43. Q->front = Q->front->next;
  44. delete brisani;
  45. }
  46. }

Report this snippet  

You need to login to post a comment.