-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueArray
More file actions
48 lines (43 loc) · 924 Bytes
/
QueueArray
File metadata and controls
48 lines (43 loc) · 924 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
public class QueueArray {
public static void main(String[] args){
Queue mqu = new Queue(6);
mqu.in(65);
mqu.in(83);
mqu.in(29);
mqu.in(25);
System.out.println(mqu.amount());
System.out.println(mqu.out());
System.out.println(mqu.amount());
}
}
class Queue{
private Object[] arr;
private int i = 0;
public Queue(){
arr = new Object[10];
}
public Queue(int a){
arr = new Object[a];
}
//入列
public void in(Object s){
if(i<arr.length) {
arr[i++] = s;
}else{
System.out.println("队列已满!");
}
}
//出列
public Object out(){
Object temp = arr[0];
for(int j=0;j<i;j++){
arr[j]=arr[j+1];
}
i--;
return temp;
}
// 队列中元素的个数
public int amount(){
return i;
}
}