Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- template <class T>
- class HashTable
- {
- public:
- void Insert(T x)
- {
- int hash = abs(x) % hashsize;
- if(!Exist(x))
- hashtable[hash].push_back(x);
- }
- void Delete(T x)
- {
- int hash = abs(x) % hashsize;
- for (int i = 0; i < hashtable[hash].size(); ++i)
- {
- if (hashtable[hash][i] == x)
- hashtable[hash].erase(hashtable[hash].begin()+i);
- }
- }
- bool Exist(T x)
- {
- int hash = abs(x) % hashsize;
- for (int i = 0; i < hashtable[hash].size(); ++i)
- {
- if (hashtable[hash][i] == x)
- return true;
- }
- return false;
- }
- private:
- const int hashsize = 1000000;
- vector<vector<T>> hashtable = vector<vector<T>>(hashsize,vector<T>());
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement