-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueArrayImplementation.java
More file actions
50 lines (40 loc) · 930 Bytes
/
QueueArrayImplementation.java
File metadata and controls
50 lines (40 loc) · 930 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
package DSImplementations;
public class QueueArrayImplementation {
private int[] queueArray;
private int head;
private int tail;
private int size;
public QueueArrayImplementation(int size) {
this.size = size;
queueArray = new int[size];
head = -1;
tail = -1;
}
public boolean isFull() {
return (tail == size - 1);
}
public boolean isEmpty() {
return (head == -1 || head > tail);
}
public void enqueue(int element) {
if (isFull()) {
System.out.println("Queue is full");
} else {
if (head == -1) {
head = 0;
}
tail++;
queueArray[tail] = element;
}
}
public int dequeue() {
int element = 0;
if (isEmpty()) {
System.out.println("Queue is empty");
} else {
element = queueArray[head];
head++;
}
return element;
}
}