zaglavlje - pokazivaci


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

deskripšn


Copy this code and paste it in your HTML
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. typedef int element;
  6.  
  7. struct red{
  8. int br;
  9. red *slijedeci;
  10. red *front,*rear;
  11. };
  12.  
  13.  
  14. typedef struct red *ele;
  15.  
  16. int FrontQ(red *jedan){
  17. if(jedan->rear!=jedan->front)
  18. return jedan->front->slijedeci->br;
  19. else{
  20. cout<<"Red je prazan!";
  21. exit(0);
  22. }
  23. }
  24.  
  25. void EnqueueQ(int x,red *jedan){
  26.  
  27. red *novi=new red;
  28. novi->br=x;
  29. novi->slijedeci=NULL;
  30. jedan->rear->slijedeci=novi;
  31. jedan->rear=novi;
  32.  
  33. }
  34.  
  35.  
  36. void DequeueQ(red *jedan){
  37.  
  38. red *brisani=new red;
  39. if(jedan->rear!=jedan->front){
  40. brisani=jedan->front;
  41. jedan->front=brisani->slijedeci;
  42. delete brisani;
  43.  
  44. }else{
  45. cout<<"Red je prazan!";
  46. exit(0);
  47. }
  48.  
  49. }
  50.  
  51.  
  52. void InitQ(red *jedan){
  53.  
  54. red*novi=new red;
  55. jedan->rear=novi;
  56. jedan->front=novi;
  57. novi->slijedeci=NULL;
  58.  
  59. }
  60.  
  61.  
  62. int IsEmptyQ(red *jedan){
  63. if(jedan->front==jedan->rear)
  64. return (-1);
  65. else
  66. return 0;
  67.  
  68. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.