import java.lang.*; import java.io.*; public class ssmain { public static void main(String[] args) { selfsort list=new selfsort(); BufferedReader SysIn=new BufferedReader(new InputStreamReader(System.in)); System.out.println("At each stage, enter one of:"); System.out.println(" #n to add number n to the list"); System.out.println(" ?n to ask whether number n is in the list"); System.out.println(" * to remove and view smallest number"); System.out.println(" x to exit"); System.out.println(""); while (true) { char command=' '; String rest_of_command=""; int number=0; try { command=(char)SysIn.read(); rest_of_command=SysIn.readLine(); } catch (IOException e) { } if (command==' ') { System.out.println("Command ignored"); continue; } if (command=='x') { break; } if (command=='*') { number=list.surrender_smallest(); System.out.println("retrieved "+number); continue; } try { number=Integer.parseInt(rest_of_command); } catch (NumberFormatException e) { command='b'; } if (command=='b') { System.out.println("Bad number"); continue; } if (command=='#') { list.insert(number); System.out.println("Added "+number); continue; } if (command=='?') { boolean reply=list.have_you_got(number); if (reply) System.out.println("Yes, "+number+" is present"); else System.out.println("No, "+number+" is absent"); continue; } System.out.println("Bad command"); } System.out.println("Done"); } }