Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ADD TO BinarySearchTree CLASS >>>>>
- >>>
- >>>
- >>>
- public AvlNode<String> insert (String x, AvlNode<String> t )
- {
- if (t==null){
- root = new AvlNode<>( x, null, null );
- return root;
- }
- int compareResult = x.compareTo( t.element );
- if( compareResult < 0 )
- t.left = insert( x, t.left );
- else if( compareResult > 0 )
- t.right = insert( x, t.right );
- else
- ;
- return balance( t );
- }
- int findHeight(AvlNode<String> t) {
- if (t == null)
- return 0;
- return 1 + Math.max(findHeight(t.left), findHeight(t.right));
- }
- -------------------------------------------------------------------------------------------------------------
- ADD TO Dictionary CLASS >>>>>
- >>>
- >>>
- >>>
- private void printSize(){
- System.out.println( numberOfLines );
- }
- private void printHeight(){
- System.out.println( treeObject.findHeight(treeObject.root) );
- }
- private void loadDictionary() throws IOException{
- String path = "C:/test/dictionary.txt" ;
- String [] words = OpenFile(path) ;
- for ( int i=0; i < numberOfLines ; i++ ){
- treeObject.insert(words[i],treeObject.root) ;
- }
- }
- private void insertWord(){
- Scanner scanner = new Scanner(System.in);
- String word = scanner. nextLine();
- treeObject.insert(word,treeObject.root) ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement