-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircularque.java
More file actions
59 lines (52 loc) · 1.39 KB
/
circularque.java
File metadata and controls
59 lines (52 loc) · 1.39 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
package lec14_lec15;
public class circularque {
private int[] ar ;
private int defaultsize= 10;
private int size;
private int front;
private int end ;
public circularque (){
this.ar= new int[defaultsize];
this.front=0;
this.end=0;
this.size=0;
}
public void insert(int elem){
if(isfull()){
System.out.println("full");
return;
}
this.ar[end++]=elem;
end = end%ar.length;
size++;
}
public int delete(){
if(isempty()){
System.out.println("empty");
return -1;
}
int temp =ar[front++];
// for (int i = 1; i <end ; i++) {
// ar[i-1]=ar[i];
// }
//front=front+1;
front=front%ar.length;
size--;
return temp;
}
public boolean isfull(){
return size==ar.length;
}
public boolean isempty(){
return size==0;
}
public int front() {
return ar[front];
}
public void display(){
for (int i = front; i <size ; i++) {
System.out.println(ar[(front+i)%ar.length]);
}
System.out.println();
}
}