question archive How could I implement these methods for a hash table? boolean contains(DataT item) Returns the if item exists in the hash table

How could I implement these methods for a hash table? boolean contains(DataT item) Returns the if item exists in the hash table

Subject:Computer SciencePrice: Bought3

How could I implement these methods for a hash table?

  • boolean contains(DataT item) Returns the if item exists in the hash table.
  • void remove(DataT item) Returns the key from the hash table. If the item does not exist, then a NoSuchElement exception is thrown.
  • void rehash() Increases the capacity of and internally reorganizes the hash table to accommodate and access its entries more efficiently. This method is meant to be called automatically when the number of keys in the hash table exceeds this hash table's capacity and load factor.

 

 

Method given:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

public class MyHashTable<DataType> {
   private int numBuckets = 10;
   private ArrayList<DataType>[] buckets;
   private int count = 0;
   public MyHashTable() {
      buckets = new ArrayList[numBuckets];
      for (int i = 0; i < numBuckets; i++) {
         buckets[i] = new ArrayList<DataType>();
      }
   }

 

 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE