Using the standard library queue and stack classes implement
Using the standard library queue and stack classes implement the following data structures (a) stack of queues (b) queue of deques (c) deque of stacks Test each of these structures by pushing 5 objects of 3 integers into them and corresponding output. You do not need to define any new classes; it is simply a matter of creating containers of containers of the appropriate | type (std::stack, std::queue, and std::deque) using STL containers. q1 = new LinkedList<>(); private Queue q2 = new LinkedList<>(); private int top; // Push element x onto stack. public void push(int x) { q1.add(x); top = x; } / Removes the element on top of the stack. public void pop() { while (q1.size() > 1) { top = q1.remove(); q2.add(top); } q1.remove(); Queue temp = q1; q1 = q2; q2 = temp; } // Removes the element on top of the stack. public void pop() { q1.remove(); if (!q1.isEmpty()) { top = q1.peek(); } } // Removes the element on top of the stack. public void pop() { q1.remove(); if (!q1.isEmpty()) { top = q1.peek(); } }
Solution
int stack_pop (queue_data *q) { return queue_remove (q); } void stack_push (queue_data *q, int val) { int old_count = queue_get_element_count (q), i; queue_insert (q, val); for (i=0; i