Posted By

ivarbanas on 12/03/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ivarbanas


red_polje.h


 / Published in: C++
 

Implementacija polje

  1. #include <cstdlib>
  2. #include <iostream>
  3. using namespace std;
  4. struct tpopis{
  5. int redbr;
  6. int x;
  7. int y;
  8. int z;
  9. };
  10.  
  11. struct bot{
  12. tpopis popis[10000];
  13. int front, rear;
  14. };
  15.  
  16. int addone(int i){
  17. return ((i+1)%10000);
  18. };
  19.  
  20. void initq(bot *red){
  21. red->front=0;
  22. red->rear=9999;
  23. cout<<"Red je inicijaliziran!"<<endl;
  24. };
  25.  
  26. bool isemptyq(bot *red){
  27. if(addone(red->rear)==red->front) return true;
  28. else return false;
  29. };
  30.  
  31. tpopis frontq(bot *red){
  32. if(isemptyq(red))
  33. cout<<"Red je prazan!";
  34. else return (red->popis[red->front]);
  35. };
  36.  
  37. void enqueueq(tpopis x, bot *red){
  38. if(addone(addone(red->rear))==(red->front))
  39. cout<<"Red je pun!";
  40. else {
  41. red->rear=addone(red->rear);
  42. red->popis[red->rear]=x;
  43. }};
  44.  
  45. void dequeueq(bot *red){
  46. if(isemptyq(red))
  47. cout<<"Red je prazan!";
  48. else red->front=addone(red->front);
  49. };

Report this snippet  

You need to login to post a comment.