title: HashTable (search function)
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include &lt;vector&gt;
  #include "list.cpp"
  #include &lt;cmath&gt;
  
  using namespace std;
  
  struct HashEntry{
     int key;
     List&lt;string&gt; list;
     HashEntry(int k)
     {        
           key=k;
     } 
  }; 
  
  class Hash{
    private:
           HashEntry *Table[100];
           int a;
    public:
           Hash(int A);
           void insert(string word);
           void Lookup(string word);
  };    
  
  Hash::Hash(int A)
  {
      a=A;
  }         
  
  void Hash::insert(string word)
  {
     int c=0;
     for (int i=0;i&lt;word.size();i++)
     {                                 
         int b=(int)((a^i)*(word[i]));
         c+=b;
     }
     c%=100;
     List&lt;string&gt; list;
     if (Table[c-1]==NULL)     //if the respective bucket doesnot have any string
     Table[c-1]=new HashEntry(c-1);
  
     Table[c-1]-&gt;list.insertAtTail(word);
  }                  
  
  
  void Hash::Lookup(string word)
  {
     int c=0;
     for (int i=0;i&lt;word.size();i++)
     {                                 
       int b=(int)((a^i)*(word[i]));
       c+=b;
     }
     cout&lt;&lt;"one"&lt;&lt;endl;
     c%=100;
     Table[c-1]-&gt;list.searchFor(word);
     cout&lt;&lt;"two"&lt;&lt;endl;
  }
  </code></pre>
  
  <p>I am making a hash table using seperate chaining taking.my hash function is making a polynomial equation using a constant 'a' whose power is increasing with the index of the letter in a word.(a^0xb+a^1xb+a^2xb+...) , where b is a letter in the word which is being hashed and then I take mod(100) of the final answer.The problem i am facing is in lookup function.when I test the lookup function,the searchFor() function which is in part of part Linked list class does not work although it works fine on its own and i get an segmentation fault after the cout&lt;&lt;"one" which i used to debug .I am sorry for bothering but I just can't understand the problem here.The linked list class file is below.I am just pasting the function in which i am having problem</p>
  
  <pre><code>#ifndef __LIST_H
  #define __LIST_H
  #include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  /* This class just holds a single data item. */
  template &lt;class T&gt;
  struct ListItem
  {
     vector&lt;string&gt; words;
     T value;
     ListItem&lt;T&gt; *next;
     ListItem&lt;T&gt; *prev;
  
     ListItem(T theVal)
     {
         this-&gt;value = theVal;
         this-&gt;next = NULL;
         this-&gt;prev = NULL;
     }
  };
  
  /* This is the generic List class */
  template &lt;class T&gt;
  class List
   {
   ListItem&lt;T&gt; *head;
  
   public:
    // Constructor
    List();
  
    // Copy Constructor
    List(const List&lt;T&gt;&amp; otherList);
  
    // Destructor
    ~List();
  
    // Insertion Functions
    void insertAtHead(T item);
    void insertAtTail(T item);
    void insertAfter(T toInsert, T afterWhat);
    void insertSorted(T item);
    void printList();
    // Lookup Functions
    ListItem&lt;T&gt; *getHead();
    ListItem&lt;T&gt; *getTail();
    void *searchFor(T item);
  
    // Deletion Functions
    void deleteElement(T item);
    void deleteHead();
    void deleteTail();
  
    // Utility Functions
    int length();
  };
  
  #endif
  
  template &lt;class T&gt;
  void List&lt;T&gt;::searchFor(T item)
  {    
   ListItem&lt;T&gt; *temp=head;
   if (temp!=NULL)
   {
      while (temp-&gt;next!=NULL)
      {
           T sample=temp-&gt;value;
           if (sample==item)
           {      
               cout&lt;&lt;"String found";   
               return;
           }
           temp=temp-&gt;next;
      }
      T s=temp-&gt;value;
      if (s==item)
      {
         cout&lt;&lt;"String found";        
         return;
      }
    }                   
  }
  </code></pre>