// //hash table with separate chaining // public class SCHashing { IterableLinkedList [] table; @SuppressWarnings("unchecked") public SCHashing(int capacity) { //table=(T[])(new Object[capacity]); //table=(IterableLinkedList[])(new Object[capacity]); table=(IterableLinkedList[])(new IterableLinkedList[capacity]); for(int i=0;i(); } public void add(T x) { int code=x.hashCode()%table.length; table[code].add(x); } public T find(T x) { int code=x.hashCode()%table.length; return table[code].find(x); } // public boolean remove(T x) // { // int code=x.hashCode()%table.length; // return table[code].remove(x); // } public static void main(String [] args) { class Record{ int id; String name; public Record(int _id){ this.id=_id; } public Record(int _id, String _name){ this.id=_id; this.name=_name; } public int hashCode() { //return (new Integer(id)).hashCode(); //System.out.println((new Integer(id)).hashCode()); return (new Double(id)).hashCode(); //return 0; } public boolean equals(Object o) { Record other=(Record)o; return id==other.id; } } SCHashing table=new SCHashing<>(13); table.add(new Record( 22030, "Mario")); table.add(new Record( 77840, "Peach")); table.add(new Record( 12374, "Bowser")); table.add(new Record( 43675, "Luigi")); table.add(new Record( 84146, "Toad")); int query=77840; System.out.println("ID="+query+" has name="+table.find(new Record(query)).name); } }