Answer to Question 41C-3

  //==========================================
  //             lookup
  //==========================================
  // Return the value associated with key x
  // in hash table T.  If x is not one of
  // the keys in T, return NULL.
  //==========================================
 
  const char* lookup(const char* x, const HashTable& T)
  {
    int h = strhash(x) % T.size;

    for(ListCell* p = T.A[h]; p != NULL; p = p->tail)
    {
      if(strcmp(x, p->key) == 0)
      {
        return p->item;
      }
    }
    return NULL;
  }