/
FCITqueue.java
58 lines (50 loc) · 1.13 KB
/
FCITqueue.java
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
class FCITqueue {
private FCITstudent first;
private FCITstudent last;
private int noOfStudentsInQueue;
boolean isEmpty() {
return this.getNoOfStudentsInQueue()==0;//return getFirst() == null;
}
void enqueue(FCITstudent student) {
FCITstudent oldlast = last;
last = student;
if (isEmpty())
setFirst(last);
else
oldlast.setNext(last);
setNoOfStudentsInQueue(getNoOfStudentsInQueue() + 1);
}
FCITstudent dequeue() {
FCITstudent student = getFirst();
setFirst(getFirst().getNext());
if (isEmpty())
last = null;
setNoOfStudentsInQueue(getNoOfStudentsInQueue() - 1);
student.setNext(null);
return student;
}
/**
* @return the first
*/
public FCITstudent getFirst() {
return first;
}
/**
* @param first the first to set
*/
public void setFirst(FCITstudent first) {
this.first = first;
}
/**
* @return the noOfStudentsInQueue
*/
public int getNoOfStudentsInQueue() {
return noOfStudentsInQueue;
}
/**
* @param noOfStudentsInQueue the noOfStudentsInQueue to set
*/
public void setNoOfStudentsInQueue(int noOfStudentsInQueue) {
this.noOfStudentsInQueue = noOfStudentsInQueue;
}
}