-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular_queue.java
More file actions
49 lines (48 loc) · 1.07 KB
/
circular_queue.java
File metadata and controls
49 lines (48 loc) · 1.07 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
import java.util.Scanner;
public class circular_queue {
int ar[];
int f,r;
public circular_queue(int size){
ar[]=new int[size];
f=-1;
r=-1;
}
public void input(int n){
if(! (f==r && f!=-1 || f==-1 && r==ar.length-1)){
r++;
if(r==ar.length){
r=0;
}
ar[r]=n;
}
else{
System.out.println("Queue is full");
}
}
public int output(){
if(f==-1 && r==-1){
return -9999;
}
else{
f++;
if(f==ar.length){
f=0;
}
int ret=ar[f];
if(f==r){
f=-1;
r=-1;
}
return ret;
}
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter size of the array : ");
int n=sc.nextInt();
System.out.println("Enter elements of the array : ");
int a[]=new int[n];
for(int ){
}
}
}