Question: Write a Java implementation for the following problem. You can make use of whichever of the ADTs Stack, Queue, and Deque that you need. Assume

Write a Java implementation for the following problem. You can make use of whichever of the ADTs Stack, Queue, and Deque that you need. Assume that these ADTs are already implemented, compiled and available in files Stack.class, Queue.class, Deque.class.

Input is read from the terminal (System.in). All input Strings are read and stored. The input String PRINT has a special meaning. Whenever a String that matches PRINT is read, the first stored string and the last 5 stored strings are printed. If there are not enough strings, the program should terminate as soon as it runs out of strings.

For example, if the input is:

1 2 3 4 5 6 7 8 PRINT 9 PRINT 10 11 12 13 PRINT

the output would be:

1 8 7 6 5 4 2 9 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!