java:模拟队列操作
1 import java.util.LinkedList; 2 3 public class Myqueue { 4 5 private LinkedList<Object> linkedList; 6 7 public Myqueue() { 8 linkedList = new LinkedList<>(); 9 } 10 11 public void intoMyqueue(Object o) { 12 linkedList.add(o); 13 } 14 15 public Object outMyqueue() { 16 int size = linkedList.size(); 17 18 if (size > 0) 19 return linkedList.remove(0); 20 else 21 return -1; 22 } 23 public int getSize() { 24 return linkedList.size(); 25 } 26 27 }
gogogo