forked from Ameesha15/DSA-ALGORITHMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntQ.java
More file actions
63 lines (57 loc) · 1.22 KB
/
Copy pathIntQ.java
File metadata and controls
63 lines (57 loc) · 1.22 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
53
54
55
56
57
58
59
60
61
62
public class IntQ {
private int [] q;
private int size;
private int total;
private int front;
private int rear;
public IntQ(){
size = 100;
total = 0;
front = 0;
rear = 0;
q = new int[size];
}
public IntQ(int size){
this.size = size;
total = 0;
front = 0;
rear = 0;
q = new int[size];
}
public boolean enqueue(int item){
if(isFull()){
return false;
}
else{
total++;
q[rear] = item;
//rear++; there is a problem!!
rear = (rear + 1)%size;//in order to back to
return true;
}
}
public int dequeue(){
int item = q[front];
total--;
//front ++; there is a problem too
front = (front+1)%size;
return item;
}
public boolean isFull(){
if(size == total){
return true;
}
else{
return false;
}
}
public void showAll(){
int f = front;
if(total!= 0){
for(int i = 0;i<total;i++){
System.out.println(""+q[f]);
f=(f+1)%size;
}
}
}
}