title: C++ Linked List segmentation fault
body: <p>I'm getting a segmentation fault in the removeElement() function. _buckets is
  an array of HashTableVoidEntry pointers. This project is supposed to implement
  a simple hash table that stores names.</p>
  
  <p>GDB is telling me that the "else" line in this else block in the
  removeElement() function is where it crashes. Can anyone pinpoint the problem
  please? I have no idea how to fix this. I'm trying to set up conditions to
  check where the element is at in the linked list. The first "if" block tells me
  if the element I want to remove is at the head. The "else if" block tells me if
  it's at the end, and the else block is for anywhere else in the list. I'm still
  learning linked lists so I'm sure I'm making a stupid error.</p>
  
  <pre><code>    else
      {
          prev-&gt;_next = e-&gt;_next;
          delete e;
          return true;
      }
  EleHashTableVoid::HashTableVoid()
  {
      _buckets = (HashTableVoidEntry**)malloc(TableSize * sizeof(HashTableVoidEntry*));
      for(int i = 0; i &lt; TableSize; i++)
      {
          _buckets[i] = NULL;
      }
  }
  // Removes an element in the hash table. Return false if key does not exist.
  bool HashTableVoid::removeElement(const char * key)
  {
      int h = hash(key);
      HashTableVoidEntry * e = _buckets[h];
      HashTableVoidEntry * prev = NULL;
      while((e != NULL) &amp;&amp; (strcmp(key, e-&gt;_key) != 0))
      {
          prev = e;
          e = e-&gt;_next;
      }
      if(e != NULL)
      {
          if(prev == NULL)
          {
              if(e == _buckets[h])
              {
                  _buckets[h] = e -&gt; _next;
                  delete e;
                  return true;
              }
          }
          else if(e -&gt; _next == NULL)
          {
              prev-&gt;_next = NULL;
              delete e;
              return true;
          }
          else
          {
              prev-&gt;_next = e-&gt;_next;
              delete e;
              return true;
          }
      }
      else
      {
          return false;
      }
  }
  </code></pre>