import java.util.*; public class FindName { public static void main(String[] args) { SearchStructure students = new MyHashTable(10); students.insert(new Integer(37123)); students.insert(new Integer(37980)); students.insert(new Integer(37556)); students.insert(new Integer(37406)); students.insert(new Integer(37553)); students.insert(new Integer(37643)); students.insert(new Integer(37778)); System.out.print(students); } } class MyHashTable implements SearchStructure { private LinkedList[] table; private int size; public MyHashTable(int size) { table = new LinkedList[size]; this.size = size; for (int row = 0; row < size; row++) table[row] = new LinkedList(); } public void insert(Object key) { // hash key to get bucket number // append key to list at that bucket table[hash(key)].add(key); } public void delete(Object key) { // hash key to get bucket number // walk list at that buck and remove ID table[hash(key)].remove(key); } public boolean search(Object key) { // hash key to get bucket number // look for key by walking list at bucket return table[hash(key)].contains(key); } public int size() { return size; } // convert key into an integer // use last digit (simple, but bad): public int hash(Object key) { return (((Integer) key).intValue() % 10); } public String toString() { String s = ""; for (int row = 0; row < size; row++) s += row+": "+table[row]+"\n"; return s; } }