-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSection_6_6_Queues.java
More file actions
61 lines (40 loc) · 1.72 KB
/
Section_6_6_Queues.java
File metadata and controls
61 lines (40 loc) · 1.72 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
54
55
56
57
58
59
60
61
/**
* Queue interface methods
* boolean add(E e)
Inserts the specified element into this queue if it is possible to do so
immediately without violating capacity restrictions, returning true upon success
and throwing an IllegalStateException if no space is currently available
* E element()
Retrieves, but does not remove, the head of this queue
* boolean offer(E e)
Inserts the specified element into this queue if it is possible to do so
immediately without violating capacity restrictions
* E peek()
Retrieves, but does not remove, the head of this queue, or returns null if this
queue is empty
* E poll()
Retrieves and removes the head of this queue, or returns null if this queue is
empty
* E remove()
Retrieves and removes the head of this queue.
*/
import java.util.LinkedList;
import java.util.Queue;
public class Section_6_6_Queues {
public static void main(String[] arguments){
Queue<Integer> numsQueue = new LinkedList<Integer>();
numsQueue.offer(10);
numsQueue.offer(20);
numsQueue.offer(30);
numsQueue.offer(40);
numsQueue.offer(50);
System.out.println("The first number in the queue is: " + numsQueue.peek());
System.out.println("The first number in the queue is: " + numsQueue.element());
System.out.println("-------------------------------------------------");
System.out.println(numsQueue);
System.out.println("'" + numsQueue.poll() + "' has been removed of the Queue...!");
System.out.println(numsQueue);
System.out.println("'" + numsQueue.remove() + "' has been removed of the Queue...!");
System.out.println(numsQueue);
}
}