Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- using namespace std;
- struct nod{int info;nod*leg;};
- nod*vf;
- void creare(nod*&vf)
- { nod*p;
- int n,i;
- vf=new nod;
- vf->leg=NULL;
- cout<<"dati prima valoare";
- cin>>vf->info;
- cout<<"dati numarul de noduri";
- cin>>n;
- for(i=2;i<=n;i++)
- { p=new nod;
- cout<<"dati valoarea";
- cin>>p->info;
- p->leg=vf;
- vf=p;
- }
- }
- void afisare(nod*vf)
- { nod*p;
- p=vf;
- while(p!=NULL)
- { cout<<p->info<<" ";
- p=p->leg;}
- }
- void stergerevalk(nod*&vf, int k)
- { nod *q, *r, *p;
- while(vf->info==k)
- {nod*p=vf;
- p=p->leg; ///stergem nodurile cu val k daca sunt consecutive la inceputul listei
- delete vf;
- vf=p;
- }
- p=vf;
- while(p->leg->leg!=NULL)
- { if(p->leg->info==k)
- { q=p->leg;
- r=q->leg; ///stergem nodurile cu val k din interiorul listei
- p->leg=r;
- delete q;
- }
- p=p->leg;
- }
- }
- int main()
- {
- creare (vf);
- afisare(vf);
- cout<<endl;
- stergerevalk(vf,5);
- afisare(vf);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement