//queue implementation using linked list //Author: Konstantin Voevodski //Date: 6/4/07 public class myLinkedQueue { private static class Node { public AnyType data; public Node next; public Node(AnyType d, Node n) { data = d; next = n; } } private Node head; private Node tail; public myLinkedQueue() { head = null; tail = null; } public boolean isEmpty() { return(head == null); } public void enqueue(AnyType x) { if(head != null) { tail.next = new Node(x,null); tail = tail.next; } else { head = tail = new Node(x,null); } } public AnyType dequeue() { if(isEmpty()) { throw new java.util.NoSuchElementException(); } AnyType v = head.data; head = head.next; return v; } }