java的队列实现
public class LinkQueue {
Node head = null;
Node tail = null;
boolean isEmpty(){
if(head==null)
return true;
else
return false;
}
void put(T data){
Node newNode = new Node(data);
if(head==tail && head==null){
newNode.next = tail;
tail = head = newNode;
}else{
tail.next = newNode;
tail = newNode;
}
}
T pop(){
if(!isEmpty()){
Node popNode= head;
head = head.next;
return popNode.data;
}else{
tail=head=null;
return null;
}
}
public static void main(String[] args) {
LinkQueue linkQueue = new LinkQueue();
linkQueue.put(1);
linkQueue.put(11);
linkQueue.put(111);
linkQueue.put(1111);
linkQueue.put(11111);
while(!linkQueue.isEmpty()){
System.out.println(linkQueue.pop());
}
}
}
class Node{
E data;
Node next = null;
public Node() {
}
Node(E data){
this.data = data;
}
}
