Pagini recente » Istoria paginii utilizator/mategm | Istoria paginii utilizator/raoul_16 | Diferente pentru utilizator/stay_awake77 intre reviziile 51 si 15 | Profil Vali_nnn | Cod sursa (job #282992)
Cod sursa(job #282992)
#include <iostream>
#define p 1099177
using namespace std;
struct NOD
{
int val;
struct NOD *next;
};
void add (int);
void remove (int);
void search (int);
NOD* list[p];
int n;
int main()
{
int i, op, x;
freopen ("hashuri.in", "r", stdin);
freopen ("hashuri.out", "w", stdout);
cin >> n;
for (i = 1; i <= n; i++)
{
cin >> op >> x;
if (op == 1)
{
add (x);
}
else if (op == 2)
{
remove (x);
}
else
{
search (x);
}
}
return 0;
}
void search (int x)
{
NOD *t;
t = list[x%p];
while (t)
{
if (t->val == x)
{
cout << "1\n";
return;
}
t = t->next;
}
cout << "0\n";
}
void remove (int x)
{
NOD *t, *u;
long indice=x%p;
if (!list[indice])
{
return;
}
else
{
t = list[indice];
if (t->val == x)
{
list[indice] = t->next;
delete t;
}
else
{
u = t;
while (1)
{
if (!t->next) return;
t = t->next;
if (t->val == x)
{
u->next = t->next;
delete t;
return;
}
u = t;
}
}
}
}
void add (int x)
{
NOD *t;
long indice=x%p;
if (!list[indice])
{
list[x%p] = new NOD;
t = list[indice];
t->val = x;
t->next = 0;
}
else
{
t = list[indice];
while (t->next)
{
if (t->val == x)
return;
t=t->next;
}
/* if (t->next)
{
t = t->next;
}
else
{*/
t->next = new NOD;
t = t->next;
t->val = x;
t->next = NULL;
}
}