Posted By

dekisanta on 11/22/10


Tagged

red Queue


Versions (?)

red_polje.h


 / Published in: C++
 

URL: dekisanta_Z3_2

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct tred{
  5. tdata element[10000];
  6. int front, rear;
  7. };
  8.  
  9. int AddOne(int n){
  10. return((n+1)%10000);
  11. }
  12.  
  13. void InitQ(tred *Q){
  14. Q->front = 0;
  15. Q->rear = 9999;
  16. }
  17.  
  18. bool IsEmptyQ(tred *Q){
  19. if (AddOne(Q->rear) == Q->front) return 1;
  20. else return 0;
  21. }
  22. tdata FrontQ(tred *Q){
  23. if(IsEmptyQ(Q)) exit(0);
  24. else return Q->element[Q->front];
  25. }
  26.  
  27. void EnQueueQ(tdata X, tred *Q){
  28. if(AddOne(AddOne(Q->rear)) == Q->front)
  29. cout << "Red je pun." << endl;
  30. else{
  31. Q->rear = AddOne(Q->rear);
  32. Q->element[Q->rear] = X;
  33. }
  34. }
  35.  
  36. void DeQueueQ(tred *Q){
  37. if(IsEmptyQ(Q)) cout << "Red je prazan." << endl;
  38. else Q->front = AddOne(Q->front);
  39. }

Report this snippet  

You need to login to post a comment.