Zadatak 3 Antonio Å tefek


/ 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. struct que {
  6. struct qu *front, *rear;
  7. };
  8. typedef struct que queue;
  9. typedef struct qu *element;
  10. elementtype FrontQ(queue *Q){
  11. if (Q->front==Q->rear)
  12. cout << "Prazan red.";
  13. else
  14. return ((Q->front)->next)->value;
  15. }
  16. void EnqueueQ(elementtype X, queue *Q){
  17. element E = new qu;
  18. E->value = X;
  19. E->next = NULL;
  20. (Q->rear)->next = E;
  21. Q->rear = E;
  22. }
  23. void DequeueQ(queue *Q){
  24. element E;
  25. if (Q->front==Q->rear)
  26. cout << "Prazan red.";
  27. else{
  28. E = Q->front;
  29. Q->front = (Q->front)->next;
  30. delete E;
  31. }}
  32. bool IsEmptyQ(queue *Q){
  33. if (Q->front==Q->rear)
  34. return true;
  35. else
  36. return false;
  37. }
  38. void InitQ(queue *Q){
  39. element E = new qu;
  40. Q->front = E;
  41. Q->rear = E;
  42. E->next = NULL;
  43. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.