Create a hash table class/struct. Define an array that holds 27 elements. Define
ID: 3697538 • Letter: C
Question
Create a hash table class/struct.
Define an array that holds 27 elements.
Define a function called Hash(int)
-This function returns the modulo of that int by the size of the table (array).
Define an add function that takes an integer.
-This function takes the integer, determines the hash of that number by calling the above hash function, then adds it to the table using linear probing for collision resolution.
Define a function that looks up a value, it takes an integer, return -1 if the value is not in the table.
Create a main that allows the user to add and lookup items in the table.
Explanation / Answer
public class HashImplement
{
public static void main(String args[])
{
HashImplement hi=new HashImplement();
int[]array={1,2,3,4,5,6,76,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27};
HasTable<Integer,Integer> ht=new HashTable<Integer,Integer>(array.length);
for(int i=0;i<array.length;i++)
{
ht.put(i.array[i]);
}
hi.Hash(int);
}
Hash(int i)
{
i=45;
int k;
k=45%array.lngth;
System.out.println(" the modulo is:"+k);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.