Posted By

nvarsic on 12/03/11


Tagged


Versions (?)

red_pokazivac.h


 / Published in: C++
 

strukture podataka - zadatak 3

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

Report this snippet  

You need to login to post a comment.