bus error

• 11-01-2006
wind_lark
bus error
what causes the bus error in the hashtable implementation file?

Code:

```#include "Hashtable.h" // Enter your implementation here Hashtable::Hashtable(int m_that){ m = m_that; //if (!T.empty()){ for(int j=0;j<m;j++) T[j] = -1; //} } // The primary hashing formula int Hashtable::h1(int k){   return k%m; } // The secondary hashing formula int Hashtable::h2(int k){   return 1+(k % (m-1)); } // The overall (combined) hashing formula int Hashtable::h(int k,int i){   int index;   while(i<m){   index = (h1(k) + i*h2(k))%m;   if(T[index] != -1)                  //occupied slot   i++;   if(T[index] == -1)                  //empty slot   //if(index == m)   //T[index-1] = k;   //else   T[index] = k ;  // Insert value 'k' into index = h1(k) in vector T   return index;                //insertion ok, double hashing, call double hash   }     for(int j=0;j<T.size();j++){   if (T[j] == k)   return -2;  // If 'k' is already exist in the table   if(i==m)                                // else if vector T is full, all -1 slots filled up   return -1;            //this method returns -1. No change to vector T   }    }         int Hashtable::Hash_Insert(int k){   int i=0;   return h(k,i);            }                           int Hashtable::Hash_Search(int k){ if(!T.empty()){ for(int j=0;j<T.size();j++){ if (T[j] == k) return j;  // Returns the index of item 'k' in vector T if (T[j] != k) return -1;  // Returns -1 if item 'k' is not found } } }```
• 11-01-2006
SKeane
```int Hashtable::Hash_Search(int k) {     if (!T.empty())     {         for(int j=0;j<T.size();j++)         {             if (T[j] == k)                 return j;  // Returns the index of item 'k' in vector T             if (T[j] != k)                 return -1;  // Returns -1 if item 'k' is not found         }     } }```
```int Hashtable::Hash_Search(int k) {     if (!T.empty())     {         for(int j=0;j<T.size();j++)         {             if (T[j] == k)                 return j;  // Returns the index of item 'k' in vector T         }     }     return -1;  // Returns -1 if item 'k' is not found }```