Posted By

ivvuljak on 11/20/10


Tagged


Versions (?)

red_polje.h


 / Published in: C++
 

  1. using namespace std;
  2.  
  3. struct tklijent{
  4. char ime[15];
  5. char prezime[20];
  6. char transakcija[20];
  7. int god_rodenja;
  8. int stanje_rac;
  9. };
  10. typedef int element;
  11. typedef tklijent elementtype;
  12.  
  13. struct qu{
  14. elementtype elements[1000];
  15. element front,rear;
  16. };
  17.  
  18. typedef struct qu queue;
  19.  
  20. int AddOne(int n){
  21. return((n+1)%1000);
  22. }
  23.  
  24. bool IsEmptyQ(queue *red){
  25. if (AddOne(red->rear) == red->front) return true;
  26. else return false;
  27. }
  28.  
  29. elementtype FrontQ(queue *red){
  30. if (IsEmptyQ(red)){
  31. cout << "Red je prazan!" << endl;
  32. exit(1);
  33. }
  34. return red->elements[red->front];
  35. }
  36.  
  37. void EnqueueQ(elementtype x , queue *red){
  38. if (AddOne(AddOne(red->rear)) == red->front){
  39. cout << "Red je popunjen!" << endl;
  40. exit(1);
  41. }
  42. red->rear = AddOne(red->rear);
  43. red->elements[red->rear] = x;
  44. };
  45.  
  46. void DequeueQ(queue *red){
  47. if (IsEmptyQ(red)){
  48. cout << "Red je prazan!" << endl;
  49. exit(1);
  50. }
  51. red->front = AddOne(red->front);
  52. }
  53.  
  54. void InitQ(queue *red){
  55. red->front = 0;
  56. red->rear = 999;
  57. }

Report this snippet  

You need to login to post a comment.