Implement a hash table. Call your class SimpleHashTable . You are to use a String array of
Fantastic news! We've Found the answer you've been seeking!
Question:
Implement a hash table. Call your classSimpleHashTable. You are to use a String array of 10 elements to store values. Keys will be integers. Implement the following methods:
- public void put (int key, String value).. Adds value to array using key
- public String get (int key). Gets value from array using key.
- public string toString(). Prints a list of values stored in array with array index
- public static int hash(int key, int size, int r). Hash using midsquare algorithm returns calculated array index
You are to use the midsquare hash algorithm, for size 10, r=2 (as discussed in class slides) to put and get keys.
Examples for midsquare with size = 10, r =2
276 -> 276 x 276 =76176
17 % 10 =7
hash(276, 10, 2) returns 7
42 -> 42 x 42 = 1764
76 % 10 = 6
hash(42, 10, 2) returns 6
This is a simple hashtable as you can assume that all keys will map to a unique index. See MIMIR for correct output.
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date: