Pagini recente » Cod sursa (job #1445010) | Cod sursa (job #249287) | Cod sursa (job #1966706) | Cod sursa (job #59182) | Cod sursa (job #266813)
Cod sursa(job #266813)
#include<fstream.h>
ifstream citeste("hashuri.in");
ofstream scrie("hashuri.out");
struct nod{
int inf;
nod *adr;
} *p,*u,*c;
int cauta(int x){
if (p->inf==x) return 1;
c=p;
while (c->adr){
c=c->adr;
if (c->inf==x) return 1;
}
return 0;
}
void adauga(int x){
if (!cauta(x)){
c=new nod;
c->inf=x;
c->adr=0;
if (p==0) p=c;
else u->adr=c;
u=c;
}
}
void sterge(int x){
nod *d;
if(cauta(x)){
c=p;
while(c->adr){
d=c;c=c->adr;
if (c->inf==x){
d->adr=c->adr;
delete c;
break;
}
}
}
}
void citire(){
int x,y;
citeste>>x>>y;
if (x==1) adauga(y);
else if (x==2) sterge(y);
else if (x==3) scrie<<cauta(y)<<endl;
}
int main(){
int n;
citeste>>n;
for (int i=1;i<=n;i++)
citire();
return 0;
}