-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheQueue.java
More file actions
32 lines (28 loc) · 1.09 KB
/
Copy pathTheQueue.java
File metadata and controls
32 lines (28 loc) · 1.09 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
// Queue = FIFO data structure. First-In First-Out
// A collection designed for holding elemnets priot to processing
// Linear data structure
// Add = enqueue, offer()
// Remove = dequeue, poll()
import java.util.LinkedList;
import java.util.Queue;
public class TheQueue {
public static void main(String[] args) {
Queue<String> queue = new LinkedList<String>();
// Append to the queue
queue.offer("Microsoft");
queue.offer("Amazon");
queue.offer("Tesla");
queue.offer("IBM");
// remove the first input
System.out.println(queue.poll()); // ==> Microsoft
// output the last input
System.out.println(queue.element()); // ==> Microsoft
// check if the queue is Empty or not (False, True)
System.out.println(queue.isEmpty());
// Output the size of the queue
System.out.println(queue.size());
// Boolean search 1 if the object in the queue and -1 if not
System.out.println(queue.contains("IBM")); // ==> True
System.out.println(queue);
}
}