Pagini recente » Cod sursa (job #1763326) | Cod sursa (job #2533760) | Cod sursa (job #142490) | Cod sursa (job #2920372) | Cod sursa (job #963231)
Cod sursa(job #963231)
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include<vector>
#define N 44497
using namespace std;
/*
template<typename Tkey> struct nod {
Tkey key;
};*/
template<typename Tkey> class Hashtable {
private:
vector<unsigned int> H[N];
//unsigned int HMAX;
public:
/*Hashtable(unsigned int h)
{
HMAX = h;
H = new ForwardList< struct nod<Tkey> >[HMAX];
}
~Hashtable()
{
delete[] H;
}*/
void put(Tkey key)
{
if(!hasKey(key))
{
unsigned int poz;
poz = key % N;
//nod<Tkey> x;
//x.key = key;
H[poz].push_back(key);
}
}
bool hasKey(Tkey key)
{
unsigned int poz;
poz = key % N;
/*struct elem<struct nod<Tkey> >* paux;
paux = H[poz].pfirst;
while(paux && paux->info.key != key)
paux = paux->next;
return paux != NULL;*/
vector<unsigned int>::iterator it;
for(it = H[poz].begin(); it != H[poz].end(); ++it)
if(*it == key)
return true;
return false;
}
void remove(Tkey key)
{
unsigned int poz = key % N;
/*elem<nod<Tkey> >* paux = H[poz].pfirst;
while(paux && paux->info.key != key)
paux = paux->next;
H[poz].remove(paux);*/
vector<unsigned int>::iterator it;
for(it = H[poz].begin(); it != H[poz].end(); ++it)
if(*it == key)
{
H[poz].erase(it);
return;
}
}
};
int main()
{
unsigned int n;
short int op;
unsigned int x;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
scanf("%d", &n);
Hashtable<unsigned int> hash;
for(unsigned int i = 0; i < n; i++)
{
scanf("%hd", &op);
scanf("%d", &x);
if(op == 1)
hash.put(x);
else if(op == 2)
hash.remove(x);
else
printf("%d\n", hash.hasKey(x));
}
}