Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <bits/stdc++.h>
- using namespace std;
- struct nod
- {
- int info;
- nod * urm;
- };
- void sterge(nod * & p);
- void ad_inc (nod * & p, int x);
- void afisare(nod* p);
- int main()
- {
- nod *prim = NULL;
- int nr, n;
- cin>>n;
- for(int i;i<=n;i++)
- {
- cin>>nr;
- ad_inc(prim,nr);
- }
- afisare(prim);
- return 0;
- }
- void adaugare(nod * & p, int x)
- {
- nod* nou =new nod;
- nou -> info =x;
- nou -> urm =NULL;
- if(p==NULL)
- {
- p=nou;
- }
- else
- {
- nod*ultim=p;
- while(ultim->urm!=NULL)
- ultim = ultim->urm;
- ultim -> urm=nou;
- }
- }
- void afisare(nod* p)
- {
- while (p)
- {
- cout<<p->info<<" ";
- p=p-> urm;
- }
- cout<< endl;
- }
- void ad_inc (nod * & p , int x)
- {
- if(!p)
- {
- p= new nod;
- p->info = x;
- p-> urm =NULL;
- }
- else
- {
- nod *nou;
- nou=new nod;
- nou->info=x;
- nou->urm=p;
- p=nou;
- }
- }
- void sterge(nod * & p)
- {
- nod * q;
- while(p !=NULL && p->info%2 == 0)
- {
- nod* g=p;
- p=p->urm;
- delete q;
- }
- nod * d=p;
- while(d!=NULL)
- if(d->urm->info%2==0)//de va sterge d->urm
- {
- nod*q= d->urm;
- d->urm=q->urm;
- delete q;
- }
- else
- d=d->urm;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement