Posted By


robi_kc7 on 11/22/10

Tagged


Statistics


Viewed 463 times
Favorited by 0 user(s)

Strukture_podataka_zad3


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



Copy this code and paste it in your HTML
  1. //red_pokazivac.h
  2.  
  3. typedef int elementtype;
  4. struct tre{
  5. elementtype value;
  6. re *next;
  7. };
  8.  
  9. struct tred{
  10. re *front,*rear;
  11. };
  12.  
  13. typedef tred red;
  14.  
  15.  
  16.  
  17. bool IsEmptyQ(red *Q){
  18. if(Q->rear==Q->front) return 1;
  19.  
  20. else return 0;
  21.  
  22. }
  23.  
  24. elementype FrontQ(red *Q){
  25. if(IsEmptyQ(Q)==1){
  26. return 0;}
  27. else return Q->front->next->value;
  28.  
  29. }
  30.  
  31. void EnQueueQ(elementtype x, red *Q){
  32. red novi=new red;
  33. novi->next=NULL;
  34. novi->value=x;
  35. Q->rear->next=novi;
  36. Q->rear=novi;
  37.  
  38. }
  39.  
  40. void DeQueueQ(red *Q){
  41. if(IsEmptyQ(Q)==1) return;
  42. else {
  43. red *brisi=Q->front;
  44. Q->front=Q->front->next;
  45. delete brisi;
  46.  
  47. }
  48.  
  49.  
  50. void InitQ(red *Q){
  51. Q=new red;
  52. tre *novi=new tre;
  53. Q->front=novi;
  54. Q->rear=novi;
  55. return;
  56. }
  57.  
  58.  
  59. //red_polje.h
  60.  
  61.  
  62. typedef int elementtype;
  63.  
  64. struct tred{
  65. elementtype elements[1000];
  66. int front,rear;
  67. };
  68.  
  69. typedef tred red;
  70.  
  71. int AddOne(int n) {
  72. return((n+1)%10000);
  73. }
  74.  
  75. bool IsEmptyQ(red *Q){
  76. if(AddOne(Q->front)==Q->rear) return 1;
  77.  
  78. else return 0;
  79. }
  80.  
  81. elementtype FrontQ(red *Q){
  82. if(IsEmptyQ(Q)==1) return 0;
  83.  
  84. else {
  85. return Q->elements[Q-front];
  86. }
  87. }
  88.  
  89. void EnQueueQ(elementtype x, red *Q){
  90. if(IsEmptyQ(Q)==1) return;
  91.  
  92. else {
  93. Q->rear=AddOne(Q->rear);
  94. Q->elements[Q->rear]=x;
  95. }
  96. }
  97.  
  98. void DeQueueQ(red *Q){
  99. if(IsEmptyQ(Q)==1) return;
  100.  
  101. Q->front=AddOne(Q->front);
  102.  
  103. }
  104.  
  105. void InitQ(red *Q){
  106. Q=new red;
  107. Q->front=0;
  108. Q->rear=9999;
  109. return;
  110.  
  111. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.