#include<fstream>
#include<iostream>
using namespace std;
ifstream f("l.in");
struct nod{
int info;
nod* urm;
};
nod *prim, *ultim;
void adaugs(int x)
{
nod*nou=new nod;
nou->info=x;
nou->urm=NULL;
if(prim==NULL) prim=nou;
else ultim->urm=nou;
ultim=nou;
}
void afis()
{ nod *p=prim;
while(p)
{ cout<<p->info<<" ";
p=p->urm;
}
}
void stergere(int x)
{
nod *p,*q;
p=prim;
while(p->urm!=NULL && p->urm->info!=x) p=p->urm;
if(p->urm==NULL) cout<<"Nu s-a gasit valoarea cautata";
else
{ q=p->urm;
p->urm=q->urm;
delete q;
}
}
int main()
{
int x,v;
prim=NULL;
ultim=NULL;
while(f>>x) adaugs(x);
afis();
cout<<endl;
cin>>x;
stergere(x);
afis();
system("pause");
return 0;
}
|