Posted By

anja2pet on 11/20/10


Tagged


Versions (?)

red_polje.h


 / Published in: C++
 

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

Report this snippet  

You need to login to post a comment.