-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueues.java
More file actions
52 lines (46 loc) · 1.05 KB
/
Copy pathQueues.java
File metadata and controls
52 lines (46 loc) · 1.05 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
class Queue {
int maxSize;
int[] arr;
int front;
int back;
Queue(int size) {
maxSize = size;
arr = new int[maxSize];
front = 0;
back = -1;
}
void insert(int value) {
if (back == maxSize - 1) return; // full
arr[++back] = value;
}
void delete() {
if (front > back) return; // empty
front++;
}
void display() {
if (front > back) {
System.out.println("queue is empty");
return;
}
for (int i = front; i <= back; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
void getsize() {
System.out.println(back - front + 1);
}
}
public class Queues {
public static void main(String[] args) {
Queue q = new Queue(5);
q.display();
q.insert(5);
q.insert(7);
q.insert(12);
q.display();
q.delete();
q.display();
q.getsize(); // size
}
}