-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathCar.java
More file actions
34 lines (29 loc) · 982 Bytes
/
Car.java
File metadata and controls
34 lines (29 loc) · 982 Bytes
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
import java.util.*;
public class Car {
public static void main(String[] args) {
Queue<String> carQueue = new LinkedList<>();
enqueue(carQueue, "landcruiser");
enqueue(carQueue, "porsche");
enqueue(carQueue, "hilux");
enqueue(carQueue, "lexus lc");
printQueueContents(carQueue);
while (!carQueue.isEmpty()) {
String removedCar = dequeue(carQueue);
System.out.println(removedCar+" Removed ");
}
if (carQueue.isEmpty()) {
System.out.println("The queue is empty.");
} else {
System.out.println("The queue is not empty.");
}
}
public static void enqueue(Queue<String> queue, String car) {
queue.add(car);
}
public static String dequeue(Queue<String> queue) {
return queue.poll();
}
public static void printQueueContents(Queue<String> queue) {
System.out.println("The queue: " + queue);
}
}