datoteka cirkularno polje


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

datoteka zaglavlja


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.