Posted By

Frenki on 11/22/10


Tagged

red polje implementacija


Versions (?)

red_polje.h


 / Published in: C++
 

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. struct data {
  5. int godina, racun;
  6. char ime_prezime[50], *transakcija;
  7. };
  8.  
  9. data greska={0,0,'\0','\0'};
  10.  
  11. struct red {
  12. data element[10000];
  13. int front, rear;
  14. };
  15.  
  16. int AddOne(int n) {
  17. return((n+1)%10000);
  18. }
  19.  
  20. void InitQ(red *Q) {
  21. Q->rear=9999;
  22. Q->front=AddOne(Q->rear);
  23. }
  24.  
  25. bool IsEmptyQ(red *Q) {
  26. if (AddOne(Q->rear)==Q->front) return true;
  27. return false;
  28. }
  29.  
  30. data FrontQ(red *Q) {
  31. if (IsEmptyQ(Q)) {
  32. cout << "Nema elemenata u redu!" << endl;
  33. return greska;
  34. }
  35. return Q->element[Q->front];
  36. }
  37.  
  38. void EnQueueQ(data x, red *Q) {
  39. if (AddOne(AddOne(Q->rear))==Q->front) {
  40. cout << "Red je pun!" << endl;
  41. cout << "Element nije dodan!" << endl;
  42. return;
  43. }
  44. Q->rear=AddOne(Q->rear);
  45. Q->element[Q->rear]=x;
  46. if (AddOne(AddOne(Q->rear))==Q->front) cout << "Red je pun!" << endl;
  47. }
  48.  
  49. void DeQueueQ(red *Q) {
  50. if (IsEmptyQ(Q)) {
  51. cout << "Nema elemenata u redu!" << endl;
  52. return;
  53. }
  54. Q->front=AddOne(Q->front);
  55. }

Report this snippet  

You need to login to post a comment.