public class linkQueue <E>{ private class Node<E>{ E e; Node<E> next; public Node(){} public Node(E e,Node next){ this.e=e; this.next=next; } } private Node front; private Node rear; private int size; public linkQueue(){ front=rear=null; } // public boolean empty(){ return size==0; } //插入 public boolean add(E e){ if(empty()){ front=new Node(e,null); rear=front; } else{ Node<E> newnode=new Node<E>(e,null); rear.next=newnode; rear=newnode; } size++; return true; } //出队 public Node poll(){ if(empty()){ throw new RuntimeException("空队列异常"); } else{ Node frontnode=front; front=front.next; frontnode.next=null; size--; return frontnode; } } }