-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
52 lines (39 loc) · 1.07 KB
/
Queue.java
File metadata and controls
52 lines (39 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
50
51
52
package Collection;
public class Queue {
int start = 0;
int end = 0;
public void enqueue(int data, int[] arr){
arr[start] = data;
start++;
}
public void dequeue(int[] arr) {
arr[end] = 0;
int Element = arr[end];
System.out.println("Element: " + arr[end]);
arr[end] = 0;
end++;
}
public void printQueue(int[] arr){
for(int i =end; i< start; i++){
System.out.println(arr[i]);
}
}
public static void main(String[] args) {
int[] arr = new int[10];
Queue myQueue = new Queue();
myQueue.enqueue(10, arr);
myQueue.enqueue(20, arr);
myQueue.enqueue(30, arr);
myQueue.enqueue(40, arr);
myQueue.enqueue(50, arr);
myQueue.enqueue(40, arr);
myQueue.enqueue(50, arr);
myQueue.enqueue(40, arr);
myQueue.enqueue(50, arr);
myQueue.enqueue(40, arr);
myQueue.enqueue(50, arr);
myQueue.printQueue(arr);
myQueue.dequeue(arr);
myQueue.printQueue(arr);
}
}