zaglavlje - polje


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

deskripšn


Copy this code and paste it in your HTML
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. typedef int element;
  6.  
  7. struct red{
  8. int br[1000];
  9. int front,rear;
  10.  
  11. };
  12.  
  13.  
  14. int AddOne(int i){
  15. return ((i+1)%1000);
  16. }
  17.  
  18. int FrontQ(red *jedan){
  19.  
  20. if(AddOne(jedan->rear)==jedan->front){
  21. cout<<"Red je prazan!";
  22. exit(0);
  23. }
  24.  
  25. else{
  26. return jedan->br[jedan->front];
  27. }
  28.  
  29. }
  30.  
  31. void EnqueueQ(int x,red *jedan){
  32. if(AddOne(AddOne(jedan->rear))==jedan->front){
  33.  
  34. cout<<"Red je pun!";
  35. exit(0);
  36. }else
  37. jedan->rear=AddOne(jedan->rear);
  38. jedan->br[jedan->rear]=x;
  39.  
  40.  
  41. }
  42.  
  43. void DequeueQ(red *jedan){
  44.  
  45. if(AddOne(jedan->rear)==jedan->front){
  46. cout<<"Red je prazan!";
  47. exit(0);
  48. }
  49.  
  50. else{
  51. jedan->front=AddOne(jedan->front);
  52.  
  53. }
  54. }
  55.  
  56. void InitQ(red *jedan){
  57.  
  58. jedan->rear=999;
  59. jedan->front=0;
  60.  
  61. }
  62.  
  63.  
  64. int IsEmptyQ(red *jedan){
  65.  
  66. if(AddOne(jedan->rear)!=jedan->front)
  67. return 0;
  68. else
  69. return (-1);
  70. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.