![]() |
The Deque extends the Queue interface and provides additional methods to support operation at both ends. This interface is part of the java.util package. The Deque interface does not strictly enforce the order of elements, meaning that different implementations may behave differently. The standard implementations of Deque in Java include ArrayDeque and LinkedList. In this article, we will check How to use Deque as a Stack in Java. Implement a Stack using DequeIn Java, you can use the Deque interface to implement a stack data structure. A Deque as “double-ended queue” and it provides methods to add and remove the elements from both ends. By using only, the methods from the end (push and pop), you can effectively use a Deque as a Stack. Example: Java
Output
Deque Stack: [14, 13, 12, 11] Peeked Element: 14 Is stack is Empty? false Popped Element: 14 Updated stack: [13, 12, 11] Explanation of the above Program: In this program, we can implement the basic operation of stack are push, pop, peek and isEmpty into the program.
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |