forked from rbk-org/Java_DataStructures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
43 lines (32 loc) · 668 Bytes
/
Copy pathQueue.java
File metadata and controls
43 lines (32 loc) · 668 Bytes
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
import java.util.Arrays;
public class Queue{
int [] arr=new int [3];
int front=0;
int rear=0;
int numberelem=0;
public void push(int elem){
if(numberelem<3){
arr[rear]=elem;
rear++;
numberelem++;
}
else {
System.out.println("overflow");
}
}
public void pop(){
if(numberelem>0){
arr[front]="-1";
front++;
numberelem--;
}
else{
System.out.println("queue is empty");
}
}
public void display(){
for(int i=0;i<3;i++){
System.out.println(arr[i]);
}
}
}