Skip to main content

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

  1.  import java.util.Scanner;
    
  2.  
    
  3.  /* Class AVLNode */
    
  4.  class AVLNode
    
  5.  {    
    
  6.      AVLNode left, right;
    
  7.      int data;
    
  8.      int height;
    
  9.  
    
  10.      /* Constructor */
    
  11.      public AVLNode()
    
  12.      {
    
  13.          left = null;
    
  14.          right = null;
    
  15.          data = 0;
    
  16.          height = 0;
    
  17.      }
    
  18.      /* Constructor */
    
  19.      public AVLNode(int n)
    
  20.      {
    
  21.          left = null;
    
  22.          right = null;
    
  23.          data = n;
    
  24.          height = 0;
    
  25.      }     
    
  26.  }
    
  27.  
    
  28.  /* Class AVLTree */
    
  29.  class AVLTree
    
  30.  {
    
  31.      private AVLNode root;     
    
  32.  
    
  33.      /* Constructor */
    
  34.      public AVLTree()
    
  35.      {
    
  36.          root = null;
    
  37.      }
    
  38.      /* Function to check if tree is empty */
    
  39.      public boolean isEmpty()
    
  40.      {
    
  41.          return root == null;
    
  42.      }
    
  43.      /* Make the tree logically empty */
    
  44.      public void makeEmpty()
    
  45.      {
    
  46.          root = null;
    
  47.      }
    
  48.      /* Function to insert data */
    
  49.      public void insert(int data)
    
  50.      {
    
  51.          root = insert(data, root);
    
  52.      }
    
  53.      /* Function to get height of node */
    
  54.      
    
  55.    "4. check empty");
    
  56.             System.out.println("5. clear tree");
    
  57.  
    
  58.             int choice = scan.nextInt();            
    
  59.             switch (choice)
    
  60.             {
    
  61.             case 1 : 
    
  62.                 System.out.println("Enter integer element to insert");
    
  63.                 avlt.insert( scan.nextInt() );                     
    
  64.                 break;                          
    
  65.             case 2 : 
    
  66.                 System.out.println("Enter integer element to search");
    
  67.                 System.out.println("Search result : "+ avlt.search( scan.nextInt() ));
    
  68.                 break;                                          
    
  69.             case 3 : 
    
  70.                 System.out.println("Nodes = "+ avlt.countNodes());
    
  71.                 break;     
    
  72.             case 4 : 
    
  73.                 System.out.println("Empty status = "+ avlt.isEmpty());
    
  74.                 break;     
    
  75.             case 5 : 
    
  76.                 System.out.println("\nTree Cleared");
    
  77.                 avlt.makeEmpty();
    
  78.                 break;         
    
  79.             default : 
    
  80.                 System.out.println("Wrong Entry \n ");
    
  81.                 break;   
    
  82.             }
    
  83.             /*  Display tree  */ 
    
  84.             System.out.print("\nPost order : ");
    
  85.             avlt.postorder();
    
  86.             System.out.print("\nPre order : ");
    
  87.             avlt.preorder();
    
  88.             System.out.print("\nIn order : ");
    
  89.             avlt.inorder();
    
  90.  
    
  91.             System.out.println("\nDo you want to continue (Type y or n) \n");
    
  92.             ch = scan.next().charAt(0);                        
    
  93.         } while (ch == 'Y'|| ch == 'y');               
    
  94.     }
    
  95.  }
    

Comments

  1. https://www.chegg.com/homework-help/fourth-quarter-1993-real-gdp-united-states-grew-annual-rate-chapter-11-problem-5p-solution-9780132914765-exc

    ReplyDelete

Post a Comment

Popular posts from this blog

Osmosis Data Sheet

Data Sheet: Activity - Osmosis Name Course Date Activity Data Code       Procedure I -Test Solution 1: Water Complete the tablesand questions below using your data and information found under the Background tab Data Table I Note: Difference in Final Volumes = Final Volume of Test Sol - Final Volume of Water Trial Starting Volume of Test Solution (L) Starting Volume of Water (L) Final Volume of Test Solution (L) Final Volume of Water (L) Difference in Final Volumes (L) 1 1.28 1.75 1.51 1.52 -0.01 2 1.28 2.00 1.64 1.64 0 Observations and Questions [1] Given that the final heights (and volumes) are the same for the water and test solution, what can you...
Simple Computer Science Questions Question 2 ANSWER Match the following a - 4 b - 10 c - 8 d - 6 e - 9 f - 1 g - 2 h - 7 i - 3 j - 5
Question: 7. A circular cam 200 mm in diameter rotates off centre with an eccentricity of 25 mm and operates the roller follower that is carried by the arm as shown in Fig. 23.35. ???200 mm +100mm- Spring 25 mm Fig. 23.35 The roller follower is held against the cam by means of an extension spring. Assuming that the force between the follower and the cam is approximately 250 N at the low position and 400 N at the high position. If the spring index is 7, find the diameter of wire, outside diameter of spring and the number of active coils. The maximum shear stress may be taken as 280 MPa. Use G 80 kN/mm2 ANSWER