Posted By

mgovedic on 12/02/11


Tagged

red Strukture podataka


Versions (?)

red_polje.h


 / Published in: C++
 

Zadatak 3

  1. #include<iostream>
  2. using namespace std;
  3. struct podaci{
  4. int a;
  5. int b,c,d;
  6. };
  7. typedef int element;
  8. struct reda{
  9. podaci brojevi[10000];
  10. element front,rear;
  11. };
  12.  
  13.  
  14. int AddOne(int n){
  15. return((n+1)%10000);
  16. }
  17. bool IsEmptyQ(reda *Q){
  18. if(AddOne(Q->rear)==Q->front) return 1;
  19. else return 0;
  20. }
  21. podaci FrontQ(reda *Q){
  22. if(IsEmptyQ(Q))
  23. cout<<"red je prazan"<<endl;
  24. return Q->brojevi[Q->front];
  25. }
  26. void EnQueueQ(podaci x, reda *Q){
  27. if(AddOne(AddOne(Q->rear))==Q->front)
  28. cout<<"Nije dodan novi element jer je red pun"<<endl;
  29. else{
  30. Q->rear=AddOne(Q->rear);
  31. Q->brojevi[Q->rear]=x;
  32. }
  33. }
  34. void DeQueueQ(reda *Q){
  35. if(IsEmptyQ(Q))
  36. cout<<"red je prazan"<<endl;
  37. else
  38. Q->front=AddOne(Q->front);
  39. }
  40. reda *InitQ(reda *Q){
  41. Q=new reda;
  42. Q->front=0;
  43. Q->rear=9999;
  44. return Q;
  45. }

Report this snippet  

You need to login to post a comment.