-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueLinkedList.java
More file actions
46 lines (38 loc) · 799 Bytes
/
QueueLinkedList.java
File metadata and controls
46 lines (38 loc) · 799 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
34
35
36
37
38
39
40
41
42
43
44
45
46
public class QueueLinkedList<T> {
// Attributes
private LinkedListDouble<T> queue;
private int size;
// Constructors
public QueueLinkedList() {
this.queue = new LinkedListDouble<>();
this.size = 0;
}
// Methods
public boolean isEmpty() {
return size == 0;
}
public int size() {
return size;
}
public void enqueue(T data) {
queue.add(data);
size++;
}
public T dequeue() {
if (isEmpty()) {
return null;
}
size--;
return queue.remove(0);
}
public T peek() {
if (isEmpty()) {
return null;
}
return queue.get(0);
}
@Override
public String toString() {
return queue.toString();
}
}