forked from Jasmine-21/Java-FOP
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathReverse.java
More file actions
35 lines (28 loc) · 806 Bytes
/
Reverse.java
File metadata and controls
35 lines (28 loc) · 806 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
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
public class Reverse {
public static void main(String[] args) {
// TODO Auto-generated method stub
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>();
static Stack<Integer> s = new Stack<>();
public static void func() {
int max = q.peek();
int size = q.size();
for (int i = 0; i < size; i++) {
s.push(q.remove());
}
for (int i = 0; i < size; i++) {
q.add(s.pop());
}
}
}