← Back to Classes
Question 188
Build a Generic Queue with Two Slots
Build a Generic Queue with Two Slots
Complete theMiniQueue<T>class. It has two private fieldsfirstandsecondthat act as a two-slot queue. -add(T item)— iffirstis null, store the item there. Otherwise store it insecond. -remove()— return the value offirst, then shiftsecondintofirst, and setsecondto null. IMPORTANT: Do NOT write a main method. A hidden test will add two String values and two Integer values to separate queues, then callremove()twice on each and print the removed values in order.
Expected Output:
A B 1 2
Topics:
GenericsClasses
Code Editor
1
Tab to indent · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.