Pagini recente » Cod sursa (job #1255645) | Cod sursa (job #1728559) | Cod sursa (job #636206) | Cod sursa (job #1133057) | Cod sursa (job #1796897)
#include <iostream>
#include <fstream>
using namespace std;
#define M 123457
struct nod
{
int nr;
nod *link;
}*HT[M];
void push(int, int);
void delete_x(int, int);
int gaseste_x(int, int);
int main()
{
int n, o, x,h;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
cin >> n;
for (; n; n--)
{
cin >> o >> x;
h = x%M;
if (o == 1)
{
push(h, x);
}
else if (o == 2)
{
delete_x(h, x);
}
else
{
cout << gaseste_x(h, x) << endl;
}
}
return 0;
}
/*
void init()
{
for (int i = 0; i < M; i++)
HT[i] = 0;
}
*/
void push(int h, int x)
{
nod *a = new nod;
if (gaseste_x(h, x)) return;
a->nr = x;
a->link = HT[h];
HT[h] = a;
}
void delete_x(int h, int x)
{
nod *aux,*p;
if (HT[h]){
if (HT[h]->nr == x)
{
if (HT[h]->link == 0)
{
delete HT[h];
HT[h] = 0;
}
else
{
aux = HT[h];
HT[h] = HT[h]->link;
delete aux;
}
}
else
{
p = HT[h];
while (p->link)
{
if (p->link->nr == x)
{
aux = p->link;
p->link = aux->link;
delete aux;
break;
}
p = p->link;
}
}
}
}
int gaseste_x(int h, int x)
{
nod *p = HT[h];
while (p)
{
if (p->nr == x) return 1;
p = p->link;
}
return 0;
}