JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.*;
//Compiler version JDK 11.0.2
class Dcoder
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
Stack<Integer> stack=new Stack<Integer>();
String b="";
int no;
int a=in.nextInt();
for(int i=0;i<a;i++)
{
b=in.next();
if(b.equalsIgnoreCase("PUSH"))
{
no=in.nextInt();
stack.push(no);
}
else if(b.equalsIgnoreCase("pop"))
{
stack.pop();
}
else if(b.equalsIgnoreCase("peek"))
{
System.out.println(stack.peek());
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run