Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Node
  6. {
  7. int body;
  8. Node* next;
  9. Node* previous;
  10. Node()
  11. {
  12. body = 0;
  13. next = NULL;
  14. }
  15. };
  16.  
  17. class Queue
  18. {
  19. Node* head;
  20. Node* tail;
  21. public:
  22. Queue()
  23. {
  24. this->head = NULL;
  25. this->tail = NULL;
  26. }
  27. Queue(const Queue& obj)
  28. {
  29. this->head = obj.head;
  30. this->tail = obj.tail;
  31. }
  32. void push( int element)
  33. {
  34. Node* link = new Node;
  35. link->body = element;
  36. if (head->next != NULL)
  37. {
  38. this->head = link;
  39. this->tail = link;
  40. }
  41. else
  42. {
  43. link->body = element;
  44. tail->next = link;
  45. link->previous = tail;
  46. tail = tail->next;
  47. }
  48. }
  49. int pop()
  50. {
  51. Node* link = tail;
  52. int el = link->body;
  53. tail = tail->previous;
  54. }
  55. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement