class IntSet11 { // Destructive Set class, sets stored as unordered linked lists protected Cell list; public void delete(int n) { if(list!=null) if(list.first==n) list=list.next; else { Cell ptr; for(ptr=list; ptr.next!=null&&ptr.next.first!=n; ptr=ptr.next) {} if(ptr.next!=null) ptr.next=ptr.next.next; } } public void add(int n) { Cell ptr; for(ptr=list; ptr!=null&&ptr.first!=n; ptr=ptr.next) {} if(ptr==null) list = new Cell(n,list); } public boolean member(int n) { Cell ptr; for(ptr=list; ptr!=null&&ptr.first!=n; ptr=ptr.next) {} return (ptr!=null); } protected static class Cell { int first; Cell next; Cell(int f,Cell n) { first=f; next=n; } } public String toString() { String str="{"; if(list!=null) { str+=list.first; for(Cell ptr=list.next; ptr!=null; ptr=ptr.next) str+=","+ptr.first; } return str+"}"; } }