forked from prashantkalokhe/Hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue1.java
66 lines (54 loc) · 1.35 KB
/
Queue1.java
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
package Sample;
public class Queue1 {
private int size;
private String[] queArray;
private int front;
private int rear;
private int items;
public Queue1 (int s){
size = s;
queArray = new String[size];
front = 0;
rear = -1;
items = 0;
}
public boolean isEmpty(){
return (items == 0);
}
public boolean isFull(){
return (items == size);
}
public int size(){
return items;
}
public String peek(){
return queArray[front];
}
public void enqueue(String x){
if(isFull() == false){
queArray[++rear] = x;
items ++;
}
}
public String dequeue(){
String temp = null;
if(isEmpty() == false){
temp = queArray[front++];
items --;
}
return temp;
}
public static void main(String[] args) {
Queue1 myQueue = new Queue1(4);
myQueue.enqueue("10");
myQueue.enqueue("20");
myQueue.enqueue("30");
myQueue.enqueue("40");
System.out.println(myQueue.isFull());
System.out.println(myQueue.dequeue());
System.out.println(myQueue.isEmpty());
System.out.println(myQueue.isFull());
System.out.println(myQueue.dequeue());
System.out.println(myQueue.peek());
}
}