implementacija reda pomocu cirkularnog polja sejstefic


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



Copy this code and paste it in your HTML
  1. typedef int element;
  2.  
  3. struct qu {
  4. elementtype elements[10000];
  5. int front,rear;
  6. };
  7.  
  8. typedef struct qu queue;
  9.  
  10. int AddOne(int n) {
  11. return((n+1)%10000);
  12. }
  13.  
  14. int FrontQ(queue *Q){
  15. if (AddOne(*Q.rear)==(*Q.front)){
  16. cout<<"Red je prazan!"<<endl;
  17. }
  18. else
  19. return (*Q.elements[*Q.front])
  20. }
  21.  
  22. void EnQueueQ(int x, queue*Q){
  23. if(AddOne(AddOne(*Q.rear)))==(*Q.front){
  24. cout<<"Red je pun!"<<endl;
  25. }
  26. else {
  27. *Q.rear=AddOne(*Q.rear);
  28. *Q.elements[*Q.rear]=x;
  29. }
  30. }
  31.  
  32. void DeQueueQ(queue *Q){
  33. if(AddOne(*Q.rear)==*Q.front)){
  34. cout<<"Red je prazan!"<<endl;
  35. }
  36. else *Q.front=AddOne(*Q.front);
  37. }
  38.  
  39. void InitQ(queue *Q){
  40. *Q.front=0;
  41. *Q.rear=10000-1;
  42. }
  43.  
  44. int IsEmpty (queue Q){
  45. if (AddOne(Q.rear)==Q.front) return 1;
  46. else return 0;
  47. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.