Suppose a driver program creates and uses a Queue like this

Suppose a driver program creates and uses a Queue like this. What will print? insert is the same as. enqueue and remove is the same as. dequeue Queue myQueue = new Queue0; String result; myQueue.insert(MAAA\'); myQueue.insert(MBBB\"); result = myQueue.removeO; myQueue.insert(\"CCC\"); result = myQueue.peek0; result = myQueue.remove0: System.out.println(result); An exception will be thrown AAA CCC BBB

Solution

Answer: BBB

first we added AAA and BBB strings to queue. So Queue has these two Strings. we applied remove() method on queue so as per first in first out mechanism, String \"AAA\" will be removed. After that we added String CCC to queue. So now queue elements are \"BBB\",,\"CCC\". now we applied peek() method, it will return first element of the queue. So it will give \"BBB\". After that we removed the element. it will return first element that to be removed that is \"BBB\"

 Suppose a driver program creates and uses a Queue like this. What will print? insert is the same as. enqueue and remove is the same as. dequeue Queue myQueue =

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site