Question: A stack and queue can be viewed as a special type of list. Using a stack the elements are accessed, inserted, and deleted only

A stack and queue can be viewed as a special type of list. Using a stack the elements are accessed, inserted,

A stack and queue can be viewed as a special type of list. Using a stack the elements are accessed, inserted, and deleted only from the top of the stack. Whereas, using a queue the elements are inserted into the end (tail) of the queue, and are accessed and deleted from the beginning (head) of the queue. What is the output of the program below that implementing stack and queue (based on this definition)? (6 marks) public class TestStackQueue { public static void main(String[] args) { GenericStack stack = new GenericStack (); stack.push("Hakim"); stack.push("Akim"); stack.push("Aqim"); stack.push("Muhammad"); stack.push("Mohammad"); stack.push("Mohd"); stack.push("Muhd"); System.out.println (stack.pop()); System.out.println(stack.pop()); System.out.println("STACK: " + stack); GenericQueue queue = new GenericQueue (); queue.enqueue ("Hakim"); queue.enqueue ("Akim"); queue.enqueue ("Aqim"); queue.enqueue ("Muhammad"); queue.enqueue ("Mohammad"); queue. enqueue ("Mohd"); queue.enqueue ("Muhd"); System.out.println (queue. dequeue ()); System.out.println (queue.dequeue ()); System.out.println("QUEUE: " + queue); }//end main }//end class

Step by Step Solution

3.34 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

First lets define the GenericStack and GenericQueue classes and their respective push pop enqueue and dequeue methods according to the provided definition class GenericStack private List elements publ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!