Question: ?IN JAVA (DATA STRUCTURE AND ALGORITHMS 2ND EDITION) ?QUESTION: 11.1 Modify the hash.java program (Listing 11.1) to use quadratic probing. ( ?NOTE: Please make sure

?IN JAVA (DATA STRUCTURE AND ALGORITHMS 2ND EDITION)

?QUESTION:

11.1 Modify the hash.java program (Listing 11.1) to use quadratic probing.

(?NOTE: Please make sure to use quadratic probing.)

?Please make sure to use the main method given below:

public static void main(String[] args) throws IOException

{

int aKey;

DataItem aDataItem;

int size, n;

// get sizes

System.out.print("Enter size of hash table: ");

size = getInt();

System.out.print("Enter initial number of items: ");

n = getInt();

// make table

HashTable theHashTable = new HashTable(size);

for(int j=0; j

{

aKey = (int)(java.lang.Math.random() * 2 * size);

aDataItem = new DataItem(aKey);

theHashTable.insert(aKey, aDataItem);

}

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 key value to insert: ");

aKey = getInt();

aDataItem = new DataItem(aKey);

theHashTable.insert(aKey, aDataItem);

break;

case 'd':

System.out.print("Enter key value to delete: ");

aKey = getInt();

theHashTable.delete(aKey);

break;

case 'f':

System.out.print("Enter key value to find: ");

aKey = getInt();

aDataItem = theHashTable.find(aKey);

if(aDataItem != null)

System.out.println("Found " + aKey);

else

System.out.println("Could not find " + aKey);

break;

default:

System.out.print("Invalid entry ");

} // end switch

} // end while

} // end main()

?Please make sure the Output is same as given below: Make sure it works.

?OUTPUT:

Enter size of hash table: 29

Enter initial number of items: 19

Enter first letter of show, insert, delete, or find: s

Table: 29 30 30 3 3 29 2 7 37 ** ** 40 ** 13 ** 1 45 ** 47 48 ** 50 ** ** 53 ** 26 ** 28

Enter first letter of show, insert, delete, or find: f

Enter key value to find: 2

Found 2

Enter first letter of show, insert, delete, or find: i

Enter key value to insert: 3

Enter first letter of show, insert, delete, or find: s

Table: 29 30 30 3 3 29 2 7 37 ** ** 40 ** 13 ** 1 45 3 47 48 ** 50 ** ** 53 ** 26 ** 28

Enter first letter of show, insert, delete, or find:

?Please do as soon as possible. Make sure it works. Thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!