?????????е?java???
???????????? ???????[ 2014/3/7 11:34:14 ] ????????java ?????
???????????????????????queue????list(??)???????????????????????????????????????????????????????????????????????????????????(FIFO??First In First Out)?????п??????????????磬????????????????????????????????????????д???????????????????????????????????????????“????????”???????????????????
???????е?????У???????β???????????????????????????????
??????????Java?????е?????????????棩??
package cn.zhf.list;
public class MyQueue {
private int maxSize;//?????????
private int[] qarray;//???????????
private int front;//???????????
private int rear;//????????????
private int nItems;//?????????????
//????????????
public MyQueue(int s){
maxSize = s;
qarray = new int[maxSize];
front = 0;
rear = -1;
nItems = 0;
}
//?????β????????
public void enqueue(int i){
if(rear == maxSize - 1){
rear = -1;
}
qarray[++rear] = i;
nItems++;
}
//??????????
public int dequeue(){
int temp = qarray[front++];
if(front == maxSize){
front = 0;
}
nItems--;
return temp;
}
public int peekFront(){//?????????
return qarray[front];
}
public boolean isEmpty(){
return (nItems == 0);
}
public static void main(String[] args) {
MyQueue queue = new MyQueue(5);
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
queue.enqueue(4);
queue.enqueue(5);
while(!queue.isEmpty()){
int i = queue.dequeue();
System.out.println(i);
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11