//============================================================================ // Name : hashtab.cpp // Author : me // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include #include #include using namespace std; class HashTable1{ private: string* t; int capacity; int ht_size; public: HashTable1(int c); //konstruktor tworzący pustą tablicę o pojemności c int hashF(string s); //funkcja haszująca dla ciągu s bool insert(string s); //wstawienie ciągu s, zwraca true jeśli wstawienie nie wywołało kolizji, fals jeśli kolozja nastąpiła int search(string s); //wyszukanie ciągu s, zwraca indeks lub -1 jeśli friend ostream& operator<<(ostream& out, HashTable1& ht); }; HashTable1::HashTable1(int c) { capacity=c; t = new string[c]; for(int i = 0; i < capacity; i++) { t[i]="0"; } ht_size = 0; } int HashTable1::hashF(string s){ int i, sum; for (sum=0, i=0; i < s.length(); i++) sum += s[i]; return sum % capacity; } bool HashTable1::insert(string s){ int indeks; indeks = hashF(s); if(t[indeks]=="0") { t[indeks]=s; ht_size++; return true; } else{ for(int i = indeks+1; i