header - pokazivac


/ Published in: C++
Save to your folder(s)

Implementacija reda preko pokazivača


Copy this code and paste it in your HTML
  1. struct pacijent {
  2. int Xi, Yi, prioritet;
  3. };
  4.  
  5. struct qu {
  6. pacijent elem;
  7. qu *sljedeci;
  8. };
  9.  
  10. struct queue {
  11. qu *front, *rear;
  12. };
  13.  
  14. queue red;
  15.  
  16. void InitQ (queue &red) {
  17. qu *novi = new qu;
  18. novi->sljedeci = NULL;
  19. red.rear = novi;
  20. red.front = novi;
  21. }
  22.  
  23. void EnQueueQ (pacijent x, queue &red) {
  24. qu *novi = new qu;
  25. novi->elem = x;
  26. novi->sljedeci = NULL;
  27. (red.rear)->sljedeci = novi;
  28. red.rear = novi;
  29. }
  30.  
  31. pacijent FrontQ (queue red) {
  32. return ((red.front)->sljedeci)->elem;
  33. }
  34.  
  35. void DeQueueQ (queue &red) {
  36. qu *del = red.front;
  37. red.front = (red.front)->sljedeci;
  38. delete del;
  39. }
  40.  
  41. bool IsEmptyQ (queue red) {
  42. if (red.rear==red.front) return true;
  43. return false;
  44. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.