class IntSet17 { // Constructive Set class, implemented using unordered linked lists // delete uses recursion private Cell list; public IntSet17() { list = null; } private IntSet17(Cell l) { list = l; } public IntSet17 delete(int n) { Cell list1 = delete(n,list); return new IntSet17(list1); } private static Cell delete(int n,Cell l) { if(l==null) return null; else if(l.first==n) return l.next; else return new Cell(l.first,delete(n,l.next)); } public IntSet17 add(int n) { Cell ptr; for(ptr=list; ptr!=null&&ptr.first!=n; ptr=ptr.next) {} if(ptr==null) { Cell list1 = new Cell(n,list); return new IntSet17(list1); } else return this; } public boolean member(int n) { Cell ptr; for(ptr=list; ptr!=null&&ptr.first!=n; ptr=ptr.next) {} return (ptr!=null); } private 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+"}"; } }