我對C++很新,我正在使用HashTables創建一個程序。這是作業。這是我第一次使用和創建HashTables,所以請提前原諒我,我完全不知道我在做什麼。我現在面臨的主要問題是將我的remove()
函數合併。我可以得到代碼進行編譯,但是當我運行測試程序時,它崩潰了。該錯誤,我收到是HashTable刪除函數C++
列表迭代器不decrementable
我立足我刪除功能關閉我的教授,爲我們提供了插入功能的。只是改變了一些東西。這是我的班級HTable
和我的remove()
功能。
class HTable
{
public:
HTable(int size);
void insert( const string &s);
void remove(string key);
private:
vector<list<string>> List;
int currSize;
int tableSize;
int hash(const string &key);
int hashFunction(string key);
int HTableSize;
int *status_arr;
ostream & operator <<(ostream &);
};
remove()
功能
inline void HTable::remove(string key)
{
list<string> List;
if(find(List.begin(), List.end(), key) == List.begin())
{
List.pop_back();
}
}
總是刪除最終項目似乎是一個壞主意。 – 2013-04-11 01:34:35
由於您已經在使用'STL',只需使用'std :: remove_if()'而不是'std :: find()'。 – Chad 2013-04-11 01:44:47
此外,您的'列表列表;'對象是'remove()'函數的本地 - 是隻是複製/粘貼到您的問題的錯誤?那個對象顯然沒有內容。 –
Chad
2013-04-11 01:47:59