Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Nod {
- int info, freq;
- Nod *next;
- } *Hash[MOD];
- void Add (int x) {
- int key = x % MOD;
- Nod *node = new Nod;
- node -> info = x;
- node -> freq = 1;
- node -> next = Hash[key];
- Hash[key] = node;
- }
- void Insert (int x) {
- int key = x % MOD;
- Nod *node = Hash[key];
- while (node && node -> info != x)
- node = node -> next;
- if (!node)
- Add (x);
- else
- node -> freq ++;
- }
- void Erase (int x) {
- int key = x % MOD;
- Nod *node = Hash[key];
- while (node && node -> info != x)
- node = node -> next;
- if (node != nullptr && node -> freq > 0)
- node -> freq --;
- }
- int Find (int x) {
- int key = x % MOD;
- Nod *node = Hash[key];
- while (node != nullptr && node -> info != x)
- node = node -> next;
- if (node == nullptr)
- return 0;
- else
- return node -> freq;
- }
Add Comment
Please, Sign In to add comment