-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyQuene.java
More file actions
55 lines (45 loc) · 789 Bytes
/
Copy pathMyQuene.java
File metadata and controls
55 lines (45 loc) · 789 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
44
45
46
47
48
49
50
51
52
53
54
55
package com.graph;
import java.util.ArrayList;
public class MyQuene {
private ArrayList<Integer> quene;
public MyQuene() {
this.quene = new ArrayList<>();
}
public ArrayList<Integer> getQuene() {
return quene;
}
/**
* 入队操作
* @param value
*/
public void push(int value) {
quene.add(quene.size(), value);
}
/**
* 出队列操作
* @return
*/
public int pop() {
if (quene.size() < 1) {
System.out.println("没有元素了,出队列失败......");
return -1;
}
int index = quene.get(0);
quene.remove(0);
return index;
}
/**
* 判断队列是否为空
* @return
*/
public boolean isEmpty() {
if (quene.size() > 0) {
return false;
}
return true;
}
@Override
public String toString() {
return "MyQuene [quene=" + quene + "]";
}
}