This code uses separate chaining ...implement it using double hashing. Implement a separate-chaining table in which each integer x is hashed twice using two different hash functions h1(x) and h2(x). This will perhaps produce two different locations for x. Place x in the location that has the smaller chain.
public static void interactiveMode(Scanner input) {
int menuChoice = 0;
do {
System.out.println("\nInteractive Mode:");
System.out.println("1. Enter size of table");
System.out.println("2. Enter an integer");
System.out.println("3. Find integer");
System.out.println("4. Exit to Main Menu.");
System.out.print("Please enter a selection: ");
menuChoice = input.nextInt();
input.nextLine();
System.out.println();
switch (menuChoice) {
case 1:
System.out.print("Enter size of table: ");
int n = input.nextInt();
size=n;
a = new ArrayList[size];
for (int i = 0; i < size; i++) {
a[i] = new ArrayList();
}
print();
break;
case 2:
System.out.println("Enter an integer for the table");
int m = input.nextInt();
int index = m % size;
a[index].add(m);
print();
break;
case 3:
System.out.print("Enter an integer to find: ");
int search = input.nextInt();
if (find(search)) {
System.out.println("Integer " + search + " is in the table.");
}
else {
System.out.println("Integer " + search + " is not in the table.");
}
break;
default:
if (menuChoice != 4) {
System.out.println("Enter correct number.");
}
break;
}
} while (menuChoice != 4);
}