Advertisement
Guest User

Dictionary

a guest
Apr 29th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. ADD TO BinarySearchTree CLASS >>>>>
  2. >>>
  3. >>>
  4. >>>
  5.  
  6.  
  7.  
  8. public AvlNode<String> insert (String x, AvlNode<String> t )
  9. {
  10. if (t==null){
  11. root = new AvlNode<>( x, null, null );
  12. return root;
  13. }
  14. int compareResult = x.compareTo( t.element );
  15.  
  16. if( compareResult < 0 )
  17. t.left = insert( x, t.left );
  18. else if( compareResult > 0 )
  19. t.right = insert( x, t.right );
  20. else
  21. ;
  22. return balance( t );
  23. }
  24.  
  25. int findHeight(AvlNode<String> t) {
  26. if (t == null)
  27. return 0;
  28. return 1 + Math.max(findHeight(t.left), findHeight(t.right));
  29. }
  30.  
  31.  
  32.  
  33. -------------------------------------------------------------------------------------------------------------
  34.  
  35. ADD TO Dictionary CLASS >>>>>
  36. >>>
  37. >>>
  38. >>>
  39.  
  40.  
  41.  
  42. private void printSize(){
  43. System.out.println( numberOfLines );
  44. }
  45.  
  46. private void printHeight(){
  47. System.out.println( treeObject.findHeight(treeObject.root) );
  48. }
  49.  
  50. private void loadDictionary() throws IOException{
  51. String path = "C:/test/dictionary.txt" ;
  52. String [] words = OpenFile(path) ;
  53. for ( int i=0; i < numberOfLines ; i++ ){
  54. treeObject.insert(words[i],treeObject.root) ;
  55. }
  56. }
  57.  
  58. private void insertWord(){
  59. Scanner scanner = new Scanner(System.in);
  60. String word = scanner. nextLine();
  61. treeObject.insert(word,treeObject.root) ;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement