Pagini recente » Cod sursa (job #1197124) | Cod sursa (job #2911165) | Cod sursa (job #939694) | Cod sursa (job #2062005) | Cod sursa (job #236725)
Cod sursa(job #236725)
#include <stdio.h>
#include <stdlib.h>
#define MOD 666013
typedef struct nod { int idd; nod* next; };
int N;
nod* G[MOD];
inline nod* find_value(int x)
{
nod* f;
int list = x % MOD;
for (f = G[list]; f; f = f->next)
if (f->idd == x)
return f;
return NULL;
}
inline void insert_value(int x)
{
int list = x % MOD;
if (find_value(x) == NULL)
{
nod *tmp = new nod;
tmp->idd = x;
tmp->next = G[list];
G[list] = tmp;
}
}
inline void erase_value(int x)
{
int list = x % MOD;
nod *f, *prev;
for (f = G[list], prev = NULL; f; prev = f, f = f->next)
if (f->idd == x)
{
if (prev)
prev->next = f->next;
else
G[list] = f->next;
delete f;
return ;
}
}
int main()
{
int op, x;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
for (scanf("%d", &N); N; --N)
{
scanf("%d %d", &op, &x);
if (op == 1) // inserare
{
insert_value(x);
continue;
}
if (op == 2) // stergere
{
erase_value(x);
continue;
}
printf("%d\n", find_value(x) != NULL);
}
return 0;
}