Pagini recente » Cod sursa (job #1380684) | Cod sursa (job #2417632) | Cod sursa (job #2954) | Cod sursa (job #2702319) | Cod sursa (job #799701)
Cod sursa(job #799701)
#include<fstream>
#define M 999997
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int N;
struct nod{int inf; nod *next; };
nod *v[M + 1];
int H(int x)
{
return x % M;
}
void add(int x)
{
int l = H(x);
while(v[l] -> next != NULL)
v[l] = v[l] -> next;
nod *q = new nod;
q -> next =NULL;
q -> inf = x;
v[l] -> next = q;
}
void sterge(int x)
{
int l = H(x);
while(v[l] -> next != NULL && v[l] ->next -> inf != x)
{
v[l] = v[l] -> next;
}
if(v[l] -> next)
{
nod *q = new nod;
q = v[l] -> next;
if(v[l] -> next -> next != NULL)
v[l] -> next = v[l] -> next -> next;
else
v[l] -> next = NULL;
delete (q);
}
if(v[l] -> inf == x)
{
v[l] -> next = NULL;
v[l] -> inf= 0;
}
}
bool verifica(int x)
{
int l = H(x);
while(v[l] -> next != NULL)
{
if(v[l] -> inf == x)
return true;
v[l] = v[l] -> next;
}
if(v[l] -> inf == x)
return true;
return false;
}
void initializare()
{
for(int i = 1; i <= M ;i++)
{
v[i] = new nod;
v[i] -> inf = 0;
v[i] -> next = NULL;
}
}
int main()
{
fin >> N;
int op, x;
initializare();
for(int i = 1; i <= N; i++)
{
fin >> op >> x;
if(op == 1)
add(x);
if(op == 2)
sterge(x);
if(op == 3)
{
fout << verifica(x) <<'\n';
}
}
fin.close();
return 0;
}