Implement the enqueue(), dequeue(), and size() methods in C+…
Implement the enqueue(), dequeue(), and size() methods in C++ for the following queue class using a singly linked list with both head and tail pointers. The implementation should maintain the queue in FIFO (First-In, First-Out) order and must not use the linked list from STL. You may assume that dequeue() will only be called when the queue is not empty and may add a constructor (and a destructor). Example: Operations: enqueue(10), enqueue(20), enqueue(30), dequeue(), enqueue(40) Queue: 20 -> 30 -> 40 -> NULLUse this template: struct ListNode { int val; ListNode* next; ListNode(int x) : val(x), next(nullptr) {}};class Queue {public: ListNode* head; ListNode* tail; int count; // feel free to add helper functions void enqueue(int x) { // TODO } int dequeue() { // TODO } int size() { // TODO }};
Read Details