020-004-012
ArrayDeque as Stack
Medium
Problem Description
ArrayDeque as Stack
In this problem: You will use ArrayDeque as a stack (LIFO) with push/pop/peek operations and display results to standard output.
Learning Objective: Understand how to use Deque as a stack (LIFO: Last In, First Out)
Overview
ArrayDeque implements the Deque interface and can be used as both a stack and a queue. push/pop/peek provide LIFO (Last In, First Out) behavior.
Specifications
- Create an
ArrayDeque<String>as a stack - Use
pushto add"First","Second","Third"in order - Use
peekto check the top (without removing) and output - Use
popthree times to remove and output (LIFO order: Third, Second, First)
Output Format
Top: Third
Popped: Third
Popped: Second
Popped: First
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up