import java.io.*; class UseIntSets17 { // Set maintenance program with constructive set class // Includes 'undo' command // Uses tree representation of sets and includes 'treeprint' command public static void main(String[] args) throws IOException { int n=0; char ch; String line; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); IntSet18 mySet = new IntSet18(),oldSet = new IntSet18(),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; mySet = mySet.delete(n); break; case 'a' : oldSet = mySet; mySet = 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; case 't': System.out.println(mySet.treeString()); break; default: System.out.print("d - delete, a - add, m - member,"); System.out.println("u - undo, p - print, t - treeprint,"); System.out.println("q - quit"); break; } } while(ch!='q'); } }