Posted By

tomislavb on 12/03/11


Tagged

main c++ zadatak3 tbrkan strukturepodataka


Versions (?)

red_polje.h


 / Published in: C++
 

implementacija reda pomoću polja

  1. #include<iostream>
  2. using namespace std;
  3. struct atp_red {
  4. int x, y, i;
  5. short prioritet;
  6. };
  7. typedef int element;
  8. int n=9999;
  9. struct qu{
  10. atp_red elements[10000];
  11. element front,rear;
  12. };
  13. typedef struct qu queue;
  14. int AddOne (int n){
  15. return ((n+1)%10000);}
  16.  
  17. bool IsEmptyQ (queue *Q){
  18. if(AddOne(Q->rear)==Q->front) return true;
  19. else return false;}
  20.  
  21. atp_red FrontQ (queue *Q){
  22. if(!IsEmptyQ(Q)) return Q->elements[Q->front];}
  23.  
  24. void DeQueueQ (queue *Q){
  25. if (!IsEmptyQ(Q)) Q->front=AddOne(Q->front);}
  26.  
  27. void EnQueueQ (atp_red x, queue *Q){
  28. Q->rear=AddOne(Q->rear);
  29. Q->elements[Q->rear]=x;}
  30.  
  31. void InitQ (queue *Q){
  32. Q->front=0;
  33. Q->rear=n;}

Report this snippet  

You need to login to post a comment.