





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






class IntSet { int[] elts; ... }
class IntSet { // rep inv: elts contains no duplicates int[] elts; ... }
public boolean repOK() { ...check for duplicates in elts... }
class IntSet { int[] elts; int[] getElements () { return elts; } }
class Stack { class Entry { Element elt; Entry next; Entry(Element i, Entry n) { elt = i; next = n; } } Entry theStack; void push(Element i) { theStack = new Entry(i, theStack); } Element pop() throws EmptyStackException { if (theStack == null) throw new EmptyStackException(); else { Element i = theStack.elt; theStack = theStack.next; return i; }}}
Stack is = new Stack(); Integer i; is.push(new Integer(3)); is.push(new Integer(4)); i = is.pop();