Impl reda pomocu pokazivaca


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

Implementacija reda pomoću pokazivača


Copy this code and paste it in your HTML
  1. struct qu {
  2. elementtype value;
  3. struct qu *next;
  4. };
  5.  
  6. struct que {
  7. struct qu *front,*rear;
  8. };
  9.  
  10. typedef struct que queue;
  11. typedef struct qu *element;
  12.  
  13. elementtype FrontQ(queue *Q) {
  14. if ((*Q).front==(*Q).rear) {
  15. printf("Red je prazan");
  16. exit(0);
  17. }
  18. else
  19. return((*(*(*Q).front).next).value);
  20. }
  21.  
  22. void EnqueueQ( elementtype x,queue *Q) {
  23. element e;
  24. e=(struct qu *)malloc(sizeof(struct qu));
  25. (*e).value=x;
  26. (*e).next=NULL;
  27. (*(*Q).rear).next=e;
  28. (*Q).rear=e;
  29. }
  30.  
  31. void DequeueQ(queue *Q) {
  32. element e;
  33. if ((*Q).front==(*Q).rear) {
  34. printf("Red je prazan");
  35. exit(0);
  36. }
  37. else {
  38. e=(*Q).front;
  39. (*Q).front=(*(*Q).front).next;
  40. free(e);
  41. }
  42. }
  43.  
  44. void InitQ(queue *Q) {
  45. element e;
  46. e=(struct qu *)malloc(sizeof(struct qu));
  47. (*Q).front=e;
  48. (*Q).rear=e;
  49. (*e).next=NULL;
  50. }
  51.  
  52. int IsEmptyQ(queue *Q){
  53. if ((*Q).front==(*Q).rear)
  54. return(-1);
  55. else
  56. return(0);
  57. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.