Posted By

ledalink on 11/22/10


Tagged

sp zadatak3


Versions (?)

Red_polje.h


 / Published in: C++
 

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. typedef int element;
  6.  
  7. struct red{
  8. tpodaci rbr[1000];
  9. int front,rear;
  10.  
  11. };
  12.  
  13. int AddOne(int i){
  14. return ((i+1)%1000);
  15. }
  16.  
  17.  
  18. tpodaci 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->rbr[jedan->front];
  27. }
  28.  
  29. }
  30.  
  31. void EnQueueQ(tpodaci 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->rbr[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  

You need to login to post a comment.