-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueArray.java
More file actions
84 lines (81 loc) · 1.21 KB
/
Copy pathQueueArray.java
File metadata and controls
84 lines (81 loc) · 1.21 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.*;
class QueueArray{
static int r=-1;
static int f=-1;
static int queue[]=new int[5];
public static void main(String[] args) {
Scanner s= new Scanner(System.in);
boolean b=true;
while(b){
System.out.println("enter the function to perform 1:to d=insert 2:to delete 3:to print ");
int z=s.nextInt();
switch(z)
{
case 1:{
int a=s.nextInt();
insertion(queue,a);
break;
}
case 2:{
deletion(queue);
break;
}
case 3:{
print(queue);
break;
}
default:{
System.out.println("GOOD BYE");
b=false;
break;
}
}
}
}
static void insertion(int queue[],int a){
if(overflow()){
System.out.println("cant insert");
}
else{
if(r==-1&&f==-1)
{
r++;
f++;
queue[r]=a;
}
else{
r++;
queue[r]=a;
}
}
}
static void deletion(int queue[]){
if(underflow()){
System.out.println("cant delete");
}
else{
f++;
}
}
static void print(int queue[]){
for(int i=f;i<=r;i++){
System.out.println(queue[i]);
}
}
static boolean overflow(){
if(r>=4){
return true;
}
else{
return false;
}
}
static boolean underflow(){
if(r==-1&&f==-1){
return true;
}
else{
return false;
}
}
}