-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicQueueOperations.java
More file actions
39 lines (35 loc) · 1.07 KB
/
Copy pathBasicQueueOperations.java
File metadata and controls
39 lines (35 loc) · 1.07 KB
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
29
30
31
32
33
34
35
36
37
38
39
package StackAndQueues_Exercises;
import java.util.ArrayDeque;
import java.util.Scanner;
public class BasicQueueOperations {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = Integer.parseInt(scan.next());
int S = Integer.parseInt(scan.next());
int X = Integer.parseInt(scan.next());
ArrayDeque <Integer> queue = new ArrayDeque<>();
while ( N > 0){
int numbersToBeAdded = Integer.parseInt(scan.next());
queue.add(numbersToBeAdded);
N--;
}
while (S > 0){
queue.poll();
S--;
}
if(queue.isEmpty()){
System.out.println(0);
}else
if(queue.contains(X)){
System.out.println("true");
}else{
int min = Integer.MAX_VALUE;
for (int element : queue) {
if(element < min){
min = element;
}
}
System.out.println(min);
}
}
}