-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
60 lines (46 loc) · 932 Bytes
/
Queue.java
File metadata and controls
60 lines (46 loc) · 932 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package fypScheduling;
public class Queue {
private int maxSize;
private int[] queArray;
private int front;
private int rear;
private int nItems;
private double[] worstList;
public Queue(int s) {
maxSize = s;
queArray = new int[maxSize];
front = 0;
rear = -1;
nItems = 0;
worstList = new double[maxSize];
}
public void insert(int j) {
if(isFull()) {
remove();
}
if (rear == maxSize - 1) {
rear = -1;
}
queArray[++rear] = j;
nItems++;
}
public int remove() {
int temp = queArray[front++];
if (front == maxSize)
front = 0;
nItems--;
return temp;
}
public int peekFront() {
return queArray[front];
}
public boolean isEmpty() {
return (nItems == 0);
}
public boolean isFull() {
return (nItems == maxSize);
}
public int size() {
return nItems;
}
}