import java.io.*; class UseIntSets8c { // Set maintenance program, includes 'undo' command // Uses set class with copy method, implemented with linked lists // Sets implemented with IntSet11c public static void main(String[] args) throws IOException { int n=0; char ch; String line; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); IntSet11c mySet = new IntSet11c(),oldSet = new IntSet11c(),tempSet; do { System.out.print(": "); line = in.readLine(); ch = line.charAt(0); if(line.length()>1) n = Integer.parseInt(line.substring(1).trim()); switch(ch) { case 'q' : break; case 'd' : oldSet = mySet.copy(); mySet.delete(n); break; case 'a' : oldSet = mySet.copy(); mySet.add(n); break; case 'm' : if(mySet.member(n)) System.out.println("Is a member"); else System.out.println("Not a member"); break; case 'u': tempSet = mySet; mySet = oldSet; oldSet = tempSet; break; case 'p': System.out.println(mySet); break; default: System.out.print("d - delete, a - add, m - member,"); System.out.println("u - undo, p - print, q - quit"); break; } } while(ch!='q'); } }