Question
Implement a linear probe hash table that stores strings. Youll need a hash function that converts a string to an index number; see the section
Implement a linear probe hash table that stores strings. Youll need a hash function that converts a string to an index number; see the section Hashing Strings in this chapter. Assume the strings will be lowercase words, so 26 characters will suffice.
11_2
// 1. In time of insertion every no low case characters should be substituted by z.
// 2. Not existing null is displayed as #Null#.
// 3. Deleted item is represented as qzqzq and displayed as Del#
You Must use this main method:
public static void main(String[] args) throws IOException
{
String aString = new String();
StringItem stringKey, aStringItem;
int size, n, keysPerCell;
// get sizes
System.out.print("Enter size of hash table: ");
size = getInt();
keysPerCell = 10;
// make table
HashTable theHashTable = new HashTable(size);
while(true) // interact with user
{
System.out.print("Enter first letter of ");
System.out.print("show, insert, delete, or find: ");
char choice = getChar();
switch(choice)
{
case 's':
theHashTable.displayTable();
break;
case 'i':
System.out.print("Enter word to insert: ");
aString = getString();
aStringItem = new StringItem(aString);
// could add other data items here
theHashTable.insert(aStringItem);
break;
case 'd':
System.out.print("Enter string to delete: ");
aString = getString();
if( theHashTable.delete(aString) == null)
System.out.println("Can't find " + aString);
else
System.out.println("Deleted " + aString);
break;
case 'f':
System.out.print("Enter string to find: ");
aString = getString();
aStringItem = theHashTable.find(aString);
if(aStringItem != null)
{
System.out.print("Found ");
aStringItem.displayItem();
System.out.println("");
}
else
System.out.println("Can't find " + aString);
break;
default:
System.out.print("Invalid entry ");
} // end switch
} // end while
} // end main()
You must get this same output below. Thank you
Enter size of hash table: 11
Enter first letter of show, insert, delete, or find: s
Table: #Null# #Null# #Null# #Null# #Null# #Null# #Null# #Null# #Null# #Null# #Null#
Enter first letter of show, insert, delete, or find: i
Enter word to insert: one
Enter first letter of show, insert, delete, or find: d
Enter string to delete: one
Deleted one
Enter first letter of show, insert, delete, or find: s
Table: #Null# #Null# #Null# #Null# #Del# #Null# #Null# #Null# #Null# #Null# #Null#
Enter first letter of show, insert, delete, or find: i
Enter word to insert: one
Enter first letter of show, insert, delete, or find: s
Table: #Null# #Null# #Null# #Null# #Del# one #Null# #Null# #Null# #Null# #Null#
Enter first letter of show, insert, delete, or find: i
Enter word to insert: two three
Enter first letter of show, insert, delete, or find: s
Table: #Null# twozthree #Null# #Null# #Del# one #Null# #Null# #Null# #Null# #Null#
Enter first letter of show, insert, delete, or find:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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