Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package StacksAndQueues1;
- import java.util.ArrayDeque;
- import java.util.Collections;
- import java.util.Scanner;
- public class MaximumElement {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int numberOfCommands = Integer.parseInt(scanner.nextLine());
- ArrayDeque<Integer> stack = new ArrayDeque<>();
- for (int i = 0; i < numberOfCommands; i++) {
- String[] command = scanner.nextLine().split(" ");
- switch (command[0]) {
- case "1":
- stack.push(Integer.parseInt(command[1]));
- break;
- case "2":
- stack.pop();
- break;
- case "3":
- System.out.println(Collections.max(stack));
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment