Posted By

giga_games on 12/03/11


Tagged

Strukture


Versions (?)

red_polje.h


 / Published in: C++
 

URL: http://snipplr.com

implementacije reda pomoću polja

  1. struct pacijent {
  2. int prior, x, y;
  3. };
  4.  
  5. struct tred{
  6. pacijent pac[10000];
  7. int front, rear;
  8. };
  9.  
  10. tred red;
  11.  
  12. int AddOne (int mjesto) {
  13. return (mjesto+1)%10000;
  14. }
  15.  
  16. pacijent FrontQ (tred red_atp) {
  17. return red_atp.pac[red_atp.front];
  18. }
  19.  
  20. void EnQueueQ (pacijent pac, tred &red_atp) {
  21. red_atp.rear=AddOne(red_atp.rear);
  22. red_atp.pac[red_atp.rear] = pac;
  23. }
  24.  
  25. void DeQueueQ (tred &red_atp) {
  26. red_atp.front=AddOne(red_atp.front);
  27. }
  28.  
  29. bool IsEmptyQ (tred red_atp) {
  30. if (AddOne(red_atp.rear)==red_atp.front) {
  31. return true;
  32. }
  33. else {
  34. return false;
  35. }
  36. }
  37.  
  38. void InitQ (tred &red_atp) {
  39. red_atp.front=0;
  40. red_atp.rear=9999;
  41. }

Report this snippet  

You need to login to post a comment.