Question: 10. Given the following public class IntQueue { private int[] data; private int manyItems; private int front; private int rear; public void add(int d)
10. Given the following public class IntQueue { private int[] data; private int manyItems; private int front; private int rear; public void add(int d) public int remove() } IntQueue s1 = new IntQueue(); q.add(1); q.add(2); q.add(3); System.out.println(s.remove()); Draw the state of the private instance variables of q after the above code b. Complete the add and remove method of the above class. What is the time complexity of each method? c. Suppose that the queue is represented by a singly linked list. public class IntQueue { private IntNode front; private IntNode rear; int manyItems; } Draw the state of the private instance variables of q after the above code d. Complete the add and remove method of the above class in c. What is the time complexity of each method? 11. Suppose you have a stack s that contains (12 3), with 1 being the top-of-stack, and a queue q that is empty. Using no other variables and only the push() and pop() stack operations and the add() and re- move() queue operations, show a sequence of operations that leave the queue q empty and the stack s with each of the following contents. Leave the stack s with the contents (132) with 1 as top-of-stack.
Step by Step Solution
3.31 Rating (157 Votes )
There are 3 Steps involved in it
a Drawing the state of private instance variables of q after the given code IntQueue q new IntQueue qadd1 qadd2 qadd3 Systemoutprintlnqremove State of the private instance variables of q data 1 2 3 ma... View full answer
Get step-by-step solutions from verified subject matter experts
