package GenericsTest import Stack import TypeCasting import LinkedList Stack stack = new Stack() function foo() unit u = stack.pop() stack.push(u) int i = stack castTo int class SpinNode class Spinner LinkedList spinningEntities = new LinkedList() function remove(int i) destroy spinningEntities.get(i) endpackage package Stack public class Stack private SEntry dummy private SEntry top private int size = 0 construct() dummy = new SEntry(null, null) top = dummy // add an element to the end of the list function push(T elem) top = new SEntry(elem, top) size++ // get & remove the top element function pop() returns T let val = top top = top.prev size-- return val.elem // look at the top element function peek() returns T return top.elem // add all elements from elems to this stack function addAll(Stack elems) for T elem in elems push(elem) // gets the size of the stack function getSize() returns int return size // get an iterator for this stack function iterator() returns SIterator return new SIterator(dummy, top) ondestroy SEntry current = top while current != dummy let temp = current current = current.prev destroy temp destroy dummy class SEntry S elem SEntry prev construct(S elem, SEntry prev) this.elem = elem this.prev = prev class SIterator SEntry dummy SEntry current construct(SEntry dummy, SEntry top) this.dummy = dummy this.current = top // remove the current element from the list function remove() if current != dummy let cp = current.prev destroy current current = cp function hasNext() returns boolean return current.prev != dummy function next() returns Q current = current.prev return current.elem function close() destroy this endpackage