forked from jimmysingla0399/Java-FOP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximumelementmovetoend.java
More file actions
37 lines (33 loc) · 951 Bytes
/
maximumelementmovetoend.java
File metadata and controls
37 lines (33 loc) · 951 Bytes
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
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class maximumelementmovetoend {
public static void main(String arg[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int j = 0; j < n; j++) {
q.add(in.nextInt());
}
func();
System.out.println(q);
}
static Queue<Integer> q = new LinkedList<Integer>();
public static void func() {
int max = q.peek();
for (int i = 0; i < q.size(); i++) {
int del = q.remove();
if (max < del) {
max = del;
}
q.add(del);
}
int s = q.size();
for (int i = 0; i < s; i++) {
int del = q.remove();
if (del != max) {
q.add(del);
}
}
q.add(max);
}
}