- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
Latest commit
53 lines (42 loc) · 1.09 KB
/
Copy pathQueue.java
File metadata and controls
53 lines (42 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// This class implements the Queue
publicclassQueue<V> implementsQueueInterface<V>{
//TODO Complete the Queue implementation
privateNodeBase<V>[] queue;
privateintcapacity, currentSize, front, rear;
@SuppressWarnings("unchecked")
publicQueue(intcapacity) {
queue=newNodeBase[capacity];
front=rear=-1;
currentSize=0;
this.capacity=capacity;
}
publicintsize() {
returncurrentSize;
}
publicbooleanisEmpty() {
returncurrentSize<=0;
}
publicbooleanisFull() {
returncurrentSize>=capacity;
}
publicvoidenqueue(Node<V> node) {
if (isFull())
return;
if(front==-1)
front=0;
rear=(rear+1)%capacity;
queue[rear]=node;
currentSize++;
}
publicNodeBase<V> dequeue() {
if (isEmpty())
returnnull;
NodeBase<V> R = queue[front];
if (front==rear)
front=rear=-1;
else
front=(front+1)%capacity;
currentSize--;
returnR;
}
}