Question: AVL & Hashing in JAVA LANGUAGE PLEASE :) Building a data structure for countries visa applications data Step 1: build a sample data file that contains countries visa applications records in the following format: Country_Nme / Country_VISA_related_data_file_name (e.g. Germany / Germany.txt ) Step 2: using the data file created in step 1, build an AVL tree of countries nodes (use country name as key). Step 3: implement the following functions on countries AVL tree:  Print out countries sorted.  Search for a specific country  Insert a new country record.  Delete a specific country record.  Calculate tree height.  Save Tree back to file. Step 4: using the Country_VISA_related_data_file_name that stored in each tree country node, load the visa data that stored in each file. The visa record data format in these files is as follow: Passport_#/Full_name/Age/Gender/ Intended_date_of_arrival/ Intended_date_of_departure (e.g. 289332/Mamoun Nawahdah/40/M/26\4\2016/2\5\2016) Step 4: create a Hash Table using the country visa data from step 4. Step 5: implement the following functions on country visa hash table:  Print hashed table (including empty spots).  Print out table size.  Print out used hash function.  Insert a new visa record to hash table.  Search for a specific visa record.  Delete a specific visa record.  Save hash table back to file. thank you :)
ANSWER
- import java.util.Scanner; 
- /* Class AVLNode */ 
- class AVLNode 
- {
- AVLNode left, right;
- int data;
- int height;
- /* Constructor */ 
- public AVLNode() 
- {
- left = null; 
- right = null; 
- data = 0; 
- height = 0; 
- }
- /* Constructor */ 
- public AVLNode(int n) 
- {
- left = null; 
- right = null; 
- data = n; 
- height = 0; 
- }
- }
- /* Class AVLTree */ 
- class AVLTree 
- {
- private AVLNode root;
- /* Constructor */ 
- public AVLTree() 
- {
- root = null; 
- }
- /* Function to check if tree is empty */ 
- public boolean isEmpty() 
- {
- return root == null; 
- }
- /* Make the tree logically empty */ 
- public void makeEmpty() 
- {
- root = null; 
- }
- /* Function to insert data */ 
- public void insert(int data) 
- {
- root = insert(data, root); 
- }
- /* Function to get height of node */ 
- "4. check empty"); 
- System.out.println("5. clear tree"); 
- int choice = scan.nextInt(); 
- switch (choice) 
- {
- case 1 : 
- System.out.println("Enter integer element to insert"); 
- avlt.insert( scan.nextInt() ); 
- break;
- case 2 : 
- System.out.println("Enter integer element to search"); 
- System.out.println("Search result : "+ avlt.search( scan.nextInt() )); 
- break;
- case 3 : 
- System.out.println("Nodes = "+ avlt.countNodes()); 
- break;
- case 4 : 
- System.out.println("Empty status = "+ avlt.isEmpty()); 
- break;
- case 5 : 
- System.out.println("\nTree Cleared"); 
- avlt.makeEmpty(); 
- break;
- default :
- System.out.println("Wrong Entry \n "); 
- break;
- }
- /* Display tree */ 
- System.out.print("\nPost order : "); 
- avlt.postorder(); 
- System.out.print("\nPre order : "); 
- avlt.preorder(); 
- System.out.print("\nIn order : "); 
- avlt.inorder(); 
- System.out.println("\nDo you want to continue (Type y or n) \n"); 
- ch = scan.next().charAt(0); 
- } while (ch == 'Y'|| ch == 'y'); 
- }
- }
https://www.chegg.com/homework-help/fourth-quarter-1993-real-gdp-united-states-grew-annual-rate-chapter-11-problem-5p-solution-9780132914765-exc
ReplyDelete