-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueues.java
More file actions
53 lines (50 loc) · 1.24 KB
/
Copy pathqueues.java
File metadata and controls
53 lines (50 loc) · 1.24 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// PRIORITY QUEUE
import java.util.*;
import java.util.Scanner;
public class queues
{
public static void main(String[] args)
{
Queue<Integer> q = new LinkedList<Integer>();
q.add(4); // add(e): Add element in the queue
q.add(1);
q.add(10);
q.add(2);
q.add(12);
q.add(8);
System.out.println(q);
System.out.println(q.poll());
System.out.println(q.poll());
System.out.println(q.poll());
System.out.println(q.poll());
System.out.println(q.poll());
System.out.println(q.poll());
System.out.println(q.poll());
q.add(4);
q.add(1);
q.add(10);
q.add(2);
q.add(12);
q.add(8);
q.remove(2);
Iterator itr = q.iterator();
int e=0;
while(itr.hasNext())
{
e = q.poll();
}
System.out.println(e);
q.offer(0);
q.offer(2);
q.offer(1);
q.offer(5);
q.offer(1);
q.offer(13);
q.offer(5);
q.offer(3);
while(!q.isEmpty())
{
System.out.print(q.poll() + " ");
}
}
}