java队列的实现
代码
1 import java.util.*;
2 public class MyQueue {
3 private LinkedList ll=new LinkedList();
4 public void put(Object o){
5 ll.addLast(o);
6 }
7
8 public Object pop(){
9 return ll.removeFirst();
10 }
11
12 public Object get(){
13 return ll.getFirst();
14 }
15
16 public boolean empty(){
17 return ll.isEmpty();
18 }
19
20 public static void main(String[] args){
21 MyQueue mq=new MyQueue();
22 mq.put("shdio");
23 mq.put("4354");
24 mq.put("ewo");
25 while(!mq.empty()){
26 System.out.println(mq.get());
27 mq.pop();
28 }
29 }
30 }
import java.util.*;
public class MyQueue {
private LinkedList ll=new LinkedList();
public void put(Object o){
ll.addLast(o);
}
public Object pop(){
return ll.removeFirst();
}
public Object get(){
return ll.getFirst();
}
public boolean empty(){
return ll.isEmpty();
}
public static void main(String[] args){
MyQueue mq=new MyQueue();
mq.put("shdio");
mq.put("4354");
mq.put("ewo");
while(!mq.empty()){
System.out.println(mq.get());
mq.pop();
}
}
}