package Queue public class Queue private SEntry dummy private SEntry front private SEntry back private int size = 0 construct() dummy = new SEntry(null, null) front = dummy back = dummy function peek() returns T return front.elem // add an element function enqueue(T elem) if front == dummy front = new SEntry(elem, dummy) back = front front.next = dummy else back.next = new SEntry(elem, dummy) back = back.next size++ // get & remove the top element function dequeue() returns T let tmp = front front = front.next size-- return tmp.elem // add all elements from elems to this queue function addAll(Queue elems) for T elem in elems enqueue(elem) // gets the size of the queue function getSize() returns int return size // get an iterator for this queue function iterator() returns SIterator return new SIterator(dummy, front) ondestroy SEntry current = front while current != dummy let temp = current current = current.next destroy temp destroy dummy class SEntry S elem SEntry next construct(S elem, SEntry next) this.elem = elem this.next = next class SIterator SEntry dummy SEntry current construct(SEntry dummy, SEntry front) this.dummy = dummy this.current = front // remove the current element from the queue function remove() if current != dummy let cp = current.next destroy current current = cp function hasNext() returns boolean return current != dummy function next() returns Q let tmp = current current = current.next return tmp.elem function close() destroy this