Question
Make a Java program, based on ChainedTable.java (provided at the bottom), that uses chained hashing and has the methods described below. a. Complete the put
Make a Java program, based on ChainedTable.java (provided at the bottom), that uses chained hashing and has the methods described below.
a. Complete the put method to set the cursor to refer to the node that already contains the specified node. If there is no such node, then cursor should be set to null. NOTE: You are allowed to copy the solution given to Self-Test Exercise #12 (given at the bottom).
b. Add a public print method that prints the table indexes followed by all (key,element) pairs. Note that the sample code in ChainedTable.java adds new nodes at the beginning of the linked list. This means the first insertion in a list will be printed last. Below is an example using print() with an array capacity of 4 and using put(1, Hi) and put(4, Bye).
c. Provide a main method that demonstrates the methods from (a) and (b). Provide example output.
Self-Test Exercise #12 Solution:
ChainedTable.java:
public class ChainedTable { private ChainedHashNode[ ] table; public ChainedTable(int tableSize) { if (tableSize [1] 12] (4, Bye) (1, Hi) public ChainedHashNode findNodeCObject key) ChainedHashNode cursor cursor table[hash(key)] while (cursor-null) if (key.equals(cursor.key) return cursor cursorcursor.link; return nu11; [1] 12] (4, Bye) (1, Hi) public ChainedHashNode findNodeCObject key) ChainedHashNode cursor cursor table[hash(key)] while (cursor-null) if (key.equals(cursor.key) return cursor cursorcursor.link; return nu11
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started