Posted By

bagrancar on 12/03/11


Tagged


Versions (?)

Strukture_biblioteka_pokazivac


 / Published in: C++
 

URL: www.snipplr.com/strukture_biblioteka_pokazivac

Bilioteka za rješenje pomoču pokazivača.

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

Report this snippet  

You need to login to post a comment.