Stackable Interface with Undo History
hardQuestion 204Create a class UndoHistory that implements the provided Stackable interface to track text actions.
Requirements:
- Use a String[] actions array of size 10 and an int top counter (starts at 0) to track the stack.
- push(String item) adds the item at index top and increments top. Ignore if full.
- pop() decrements top and returns the item. Return "empty" if nothing to pop.
- peek() returns the item at top - 1 without removing it. Return "empty" if stack is empty.
Do NOT write a main method.
Expected output
Typed B Typed B Typed A empty
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
InterfacesClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.