Modify the given programs by adding two methods in HashTableClass: Show Full code with output Find and return the item with the maximum key; Find and return average of the keys in the hash table.   import java.util.*; public class hashTableClass {     public int tableSize;      Node[] T;     public hashTableClass()     {          System.out.println("Give the hash table size");         tableSize = Integer.parseInt(new Scanner(System.in).nextLine());         T = new Node[tableSize];         for (int i = 0; i < tableSize; i++)             T[i] = null;     }     public int hashFunction(int Key)     {          return Key % tableSize;      }     public Node Search(int Key)     {       int h = hashFunction(Key);       Node current = T[h];       while (current != null && current.item != Key)          current = current.link;       return current;     }     public void Insert(int newItem)     {         int h = hashFunction(newItem);         Node current = T[h];         Node newNode = new Node(newItem);         newNode.link = T[h];         T[h] = newNode;     }     public void Delete(int Key)     {          int h = hashFunction(Key);         if (T[h] == null) // The list is empty!             System.out.println("There is no such item!");         else         {               if (T[h].item == Key) // The only node in the list is to be deleted.                 T[h] = T[h].link;             else // The list has more than one node.             {                  Node p = searchPrevious(Key);                 if (p.link == null)                      System.out.println("There is no such item!");                 else                      p.link = p.link.link;              }          }     }     public Node searchPrevious(int key)     {         int h = hashFunction(key);         if (T[h] == null)         {             return T[h];         }         else         {             Node current = T[h];             while (!(current.link == null) && (current.link.item != key))             {                 current = current.link;             }             return current;         }     }     public void PrintHashTable()     {         for (int i = 0; i <= tableSize - 1; i++)         {              if (T[i] == null)                 System.out.println("T(" + i + "): " + "no item" + "\n");              else              {                   Node current = T[i];                  System.out.print("T(" + i + "): " + current.item + ", ");                  while (!(current.link == null))                  {                       current = current.link;                      System.out.print(+current.item + ", ");                  }              System.out.println("\n");}                }         }         }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Modify the given programs by adding two methods in HashTableClass: Show Full code with output

  1. Find and return the item with the maximum key;
  2. Find and return average of the keys in the hash table.

 

import java.util.*;
public class hashTableClass {
    public int tableSize; 
    Node[] T;
    public hashTableClass()
    { 
        System.out.println("Give the hash table size");
        tableSize = Integer.parseInt(new Scanner(System.in).nextLine());
        T = new Node[tableSize];
        for (int i = 0; i < tableSize; i++)
            T[i] = null;
    }

    public int hashFunction(int Key)
    { 
        return Key % tableSize; 
    }
    public Node Search(int Key)
    {
      int h = hashFunction(Key);
      Node current = T[h];
      while (current != null && current.item != Key)
         current = current.link;
      return current;
    }
    public void Insert(int newItem)
    {
        int h = hashFunction(newItem);
        Node current = T[h];
        Node newNode = new Node(newItem);
        newNode.link = T[h];
        T[h] = newNode;
    }
    public void Delete(int Key)
    { 
        int h = hashFunction(Key);
        if (T[h] == null) // The list is empty!
            System.out.println("There is no such item!");
        else
        {  
            if (T[h].item == Key) // The only node in the list is to be deleted.
                T[h] = T[h].link;
            else // The list has more than one node.
            { 
                Node p = searchPrevious(Key);
                if (p.link == null)
                     System.out.println("There is no such item!");
                else 
                    p.link = p.link.link;
             } 
        }
    }
    public Node searchPrevious(int key)
    {
        int h = hashFunction(key);
        if (T[h] == null)
        {
            return T[h];
        }
        else
        {
            Node current = T[h];
            while (!(current.link == null) && (current.link.item != key))
            {
                current = current.link;
            }
            return current;
        }
    }
    public void PrintHashTable()
    {
        for (int i = 0; i <= tableSize - 1; i++)
        { 
            if (T[i] == null)
                System.out.println("T(" + i + "): " + "no item" + "\n");
             else
             { 
                 Node current = T[i];
                 System.out.print("T(" + i + "): " + current.item + ", ");
                 while (!(current.link == null))
                 { 
                     current = current.link;
                     System.out.print(+current.item + ", ");
                 }
             System.out.println("\n");}
               }
        }   

    
}

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education