Posted By

ikovic on 12/03/11


Tagged

red sp c++


Versions (?)

red_pokazivaci.h


 / Published in: C++
 

URL: /

Implementacija reda pokazivańćima

  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. struct tpacijent
  8. { int rbp;
  9. int x;
  10. int y;
  11. int z;
  12. };
  13.  
  14. struct t{
  15. tpacijent vrij;
  16. t *sljedeci;
  17. };
  18.  
  19. struct q{
  20. t *front, *rear;
  21. };
  22.  
  23. void initq(q *queue){
  24. queue->front=(t*)malloc(sizeof(t));
  25. queue->front->sljedeci=NULL;
  26. queue->rear=queue->front;
  27. };
  28.  
  29. bool isemptyq(q*queue){
  30. if(queue->front==queue->rear) return true;
  31. else return false;
  32. };
  33.  
  34. void enqueueq(tpacijent x,q *queue){
  35. t *pom;
  36. pom=new t;
  37. pom->vrij=x;
  38. pom->sljedeci=NULL;
  39. queue->rear->sljedeci=pom;
  40. queue->rear=pom;
  41. };
  42.  
  43. void dequeueq(q*queue){
  44. t *pom;
  45. if(isemptyq(queue)) cout<<"Red je prazan";
  46. else{
  47. pom=queue->front;
  48. queue->front=queue->front->sljedeci;
  49. free(pom);
  50. }
  51. };
  52.  
  53. tpacijent frontq(q *queue){
  54. if(isemptyq(queue)) cout<<"Red je prazan";
  55. else return (queue->front->sljedeci->vrij);
  56. };

Report this snippet  

You need to login to post a comment.