Posted By

fkocijan on 12/02/11


Tagged

red pokazivac implenetacija


Versions (?)

Red pokazivac


 / Published in: C++
 

Implementacija reda pomocu pokazivaca koji se koristi u glavnom programu

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

Report this snippet  

You need to login to post a comment.