-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionQueue.java
More file actions
44 lines (36 loc) · 922 Bytes
/
QuestionQueue.java
File metadata and controls
44 lines (36 loc) · 922 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
import java.io.Serializable;
import java.util.LinkedList;
/**
* This class represents a queue data structure for question objects.
* @author Michael Roscoe
* @author Adrian Bolesnikov
*/
public class QuestionQueue implements Serializable {
private LinkedList<Question> list;
public QuestionQueue () {
list = new LinkedList<>();
}
public void enqueue (Question q) {
list.add(q);
}
public Question dequeue () {
return list.removeFirst();
}
public Question peek () {
return list.peekFirst();
}
public boolean isEmpty () {
return list.isEmpty();
}
public String toString () {
String s = "";
if (list != null) {
int i = 0;
while (i < list.size()) {
s += i + 1 + ". " + list.get(i).toString() + "\n";
i++;
}
}
return s;
}
}