forked from pandeyprem/DSA-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.java
41 lines (32 loc) · 824 Bytes
/
queue.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
import java.util.LinkedList;
import java.util.Queue;
public class QueueExample {
public static void main(String[] args)
{
Queue<Integer> q
= new LinkedList<>();
// Adds elements {0, 1, 2, 3, 4} to
// the queue
for (int i = 0; i < 5; i++)
q.add(i);
// Display contents of the queue.
System.out.println("Elements of queue "
+ q);
// To remove the head of queue.
int removedele = q.remove();
System.out.println("removed element-"
+ removedele);
System.out.println(q);
// To view the head of queue
int head = q.peek();
System.out.println("head of queue-"
+ head);
// Rest all methods of collection
// interface like size and contains
// can be used with this
// implementation.
int size = q.size();
System.out.println("Size of queue-"
+ size);
}
}