-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
55 lines (48 loc) · 1.28 KB
/
Copy pathQueue.java
File metadata and controls
55 lines (48 loc) · 1.28 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
public class Queue {
private int[] values;
private int length;
private int front;
private int back;
public Queue() {
this.values = new int[10];
this.length = 0;
this.front = 0;
this.back = 0;
}
public int[] get_values(){
return this.values;
}
public int get_length(){
return this.length;
}
public int get_front(){
return this.front;
}
public int get_back(){
return this.back;
}
public void enqueue(int value) {
if (this.back == this.values.length - 1) {
this.back ++;
this.length ++;
int[] new_values = new int[this.length];
System.arraycopy(this.values, 0, new_values, 0, this.values.length);
new_values[this.length - 1] = value;
this.values = new_values;
} else {
this.length ++;
this.values[back] = value;
this.back++;
}
}
public int dequeue() {
int output = this.values[this.front];
this.length = this.length - 1;
if (this.front == this.length) {
this.front = 1;
} else {
this.front ++;
}
return output;
}
}