public void Delete(int key) { int hash = hashFunc(key); HashtableDataItem head = table[hash]; HashtableDataItem prev = null; while (head != null) { if (head.getKey().Equals(key)) { break; } prev = head; head = head.next; } if (head == null) { throw new Exception("Exception: there is no such element in hashtable"); } if (prev != null) { prev.next = head.next; } else { table[hash] = head.next; } }
public double Search(int key) { int hash = hashFunc(key); HashtableDataItem head = table[hash]; while (head != null) { if (head.getKey().Equals(key)) { return(head.getValue()); } head = head.next; } throw new Exception("Exception: there is no such element in hashtable"); }
public void Insert(double value, int key) { int hash = hashFunc(key); HashtableDataItem head = table[hash]; while (head != null) { if (head.getKey().Equals(key)) { head.setValue(value); return; } head = head.next; } head = table[hash]; HashtableDataItem newItem = new HashtableDataItem(value, key, head); table[hash] = newItem; }
public HashtableDataItem(double value, int key, HashtableDataItem next) { this.value = value; this.key = key; this.next = next; }