#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 inserare(int v, int x)
{
nod *p, *nou;
p=prim;
while(p && p->info!=v) p=p->urm;
if(p==NULL) cout<<"Nu s-a gasit valoarea cautata";
else
{
nou=new nod;
nou->info=x;
nou->urm=p->urm;
p->urm=nou;
}
}
void inseraremedie()
{
}
int main()
{
int x,v;
prim=NULL;
ultim=NULL;
while(f>>x) adaugs(x);
afis();
cin>>v>>x;
inserare(v,x);
afis();
system("pause");
return 0;
}
|