Pagini recente » Cod sursa (job #1414200) | Cod sursa (job #497478) | Cod sursa (job #569660) | Cod sursa (job #827292) | Cod sursa (job #1045921)
#include <iostream>
#include <fstream>
using namespace std;
unsigned poz=299999;
struct nod
{
unsigned val;
nod *urm;
}*my_hash[299999];
ifstream f("hashuri.in");
ofstream g("hashuri.out");
void adaugare(nod *&p, unsigned n)
{
if (p==NULL){
p=new nod;
p->val=n;
p->urm=NULL;
}
else{
nod *q=new nod;
q->urm=p;
q->val=n;
p=q;
}
}
void stergere(nod *&p, unsigned x)
{
nod *q,*t=p;
while (t&&t->val!=x){
q=t;
t=t->urm;
}
if (t){
if (t==p){
p=p->urm;
delete t;
}
else
{
q->urm=t->urm;
delete t;
}
}
}
int my_find(nod *prim,unsigned x)
{
while (prim&&prim->val!=x){
prim=prim->urm;
}
if (prim)
return 1;
return 0;
}
int main()
{
unsigned n,x,i,pozitie;
short answer;
/*ifstream f("hashuri.in");
ofstream g("hashuri.out");*/
f>>n;
for (i=0;i<n;i++)
{
f>>answer;
f>>x;
pozitie=x%poz;
if (answer==1){
adaugare(my_hash[pozitie],x);
}
else if (answer==2){
stergere(my_hash[pozitie],x);}
else {
g<<my_find(my_hash[pozitie],x)<<"\n";
}
}
f.close();
g.close();
return 0;
}