-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQue18.java
46 lines (45 loc) · 1.09 KB
/
Que18.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
public class Que18 {
static Queue<Integer> queue;
static void Print()
{
while (!queue.isEmpty()) {
System.out.print( queue.peek() + " ");
queue.remove();
}
}
static void revqueue()
{
Stack<Integer> stack = new Stack<>();
while (!queue.isEmpty())
{
stack.add(queue.peek());
queue.remove();
}
while (!stack.isEmpty())
{
queue.add(stack.peek());
stack.pop();
}
}
public static void main(String args[])
{
queue = new LinkedList<Integer>();
queue.add(10);
queue.add(20);
queue.add(30);
queue.add(40);
queue.add(50);
queue.add(60);
queue.add(70);
queue.add(80);
queue.add(90);
queue.add(100);
System.out.println("Queue: \n"+queue);
System.out.println("\nReversed Queue: ");
revqueue();
Print();
}
}