Advertisement
Guest User

Tree234App

a guest
Jul 28th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1.  
  2. import java.io.*;
  3. ////////////////////////////////////////////////////////////////
  4. class Tree234App
  5. {
  6. public static void main(String[] args) throws IOException
  7. {
  8. long value;
  9. Tree234 theTree = new Tree234();
  10.  
  11. theTree.insert(50);
  12. theTree.insert(40);
  13. theTree.insert(60);
  14. theTree.insert(30);
  15. theTree.insert(70);
  16. System.out.println(theTree.minValue());
  17.  
  18. while(true)
  19. {
  20. System.out.print("Enter first letter of ");
  21. System.out.print("show, insert, or find: ");
  22. char choice = getChar();
  23. switch(choice)
  24. {
  25. case 's':
  26. theTree.displayTree();
  27. break;
  28. case 'i':
  29. System.out.print("Enter value to insert: ");
  30. value = getInt();
  31. theTree.insert(value);
  32. break;
  33. case 'f':
  34. System.out.print("Enter value to find: ");
  35. value = getInt();
  36. int found = theTree.find(value);
  37. if(found != -1)
  38. System.out.println("Found "+value);
  39. else
  40. System.out.println("Could not find "+value);
  41. break;
  42. default:
  43. System.out.print("Invalid entry\n");
  44. } // end switch
  45. } // end while
  46. } // end main()
  47. //--------------------------------------------------------------
  48. public static String getString() throws IOException
  49. {
  50. InputStreamReader isr = new InputStreamReader(System.in);
  51. BufferedReader br = new BufferedReader(isr);
  52. String s = br.readLine();
  53. return s;
  54. }
  55. //--------------------------------------------------------------
  56. public static char getChar() throws IOException
  57. {
  58. String s = getString();
  59. return s.charAt(0);
  60. }
  61.  
  62. //-------------------------------------------------------------
  63. public static int getInt() throws IOException
  64. {
  65. String s = getString();
  66. return Integer.parseInt(s);
  67. }
  68. //-------------------------------------------------------------
  69. } // end class Tree234App
  70. ////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement