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