package com.my; /** * 链式队列 * @author wanjn * */ public class LinkedQueue { private Node head; private int size; private Node last; //入队列 public void add(Object value){ if (head ==null) { head =last = new Node(null, value); }else { last.next = new Node(null, value); last = last.next; } } //出队列 public Object poll(){ Object oldValue =null; if (head!=null) { oldValue = head.value; head = head.next; } return oldValue; } @Override public String toString() { Node temp = head; String result= ""; while (temp!=null) { result +=temp.value+" ,"; temp = temp.next; } return result; } private class Node{ Node next; Object value; Node(Node next,Object value){ this.next = next; this.value = value; } } }