ABC cor3


Please download to get full document.

View again

of 3
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.


Publish on:

Views: 9 | Pages: 3

Extension: TXT | Download: 0

  #include <iostream>using namespace std; struct nod{int inf;nod *st,*dr,*par;};void Adauga(nod* &r,int info,nod* aux){if(r){r!ne nod;r>inf!info;r>st!r>dr!$%;r>par!aux;}elseif(info<r>inf) Adauga(r>st,info,r);else if(info>r>inf) Adauga(r>dr,info,r); else cout<<'nformatie duplicat';}void reare(nod* &r){int info,n;cout<<'numar de noduri ';cin>>n;for(int i!+;i<n;i){cout<<'informatia nodului '<<i<<--;cin>>info;Adauga(r,info,r);}}nod* .etermina/minim(nod *p){ 0ile(p>st) { p!p>st; }return p;}nod* .etermina/maxim(nod *p){ 0ile(p>dr) { p!p>dr; }return p;}nod* succesor(nod *p){ if(p>dr!!$%){if(p>par!$%) return p>par;else cout<<'$odul nu are succesor';} else{p!.etermina/minim(p>dr); return p;}  }nod* predecesor(nod *p){ if(p>st!!$%) cout<<'$odul nu are predecesor'; else{p!.etermina/maxim(p>st); return p;}}nod* auta(nod *p,int x) 11 returnea2a nodul care va fi sters, stocat in ns{if(p) {cout<<'$u sa gasit elem'<<endl; return +;}else if(p>inf<x) { p!p>dr; return auta(p,x); }else if(p>inf>x) { p!p>st; return auta(p,x); }else { cout<<'3a gasit elem cu val '<<p>inf<< endl; return p;}}void 3terge(nod* &r){ nod* ns;int x; cout<<'3a se stearga elem cu val'; cin>>x; ns!auta(r,x);if(ns!!+) cout<<'nformatia '<<ns>inf<<' $% exista in nici un nod al ar4orelui'<<endl;elseif(ns>dr!!ns>st) 11in ca2ul in care nodul cu inf x e frun2a{if(ns>inf<ns>par>inf) ns>par>st!+; else ns>par>dr!+; delete ns; 11eli4erea2a 2ona de memorie ocupata de elem sters}elseif(ns>dr!!+ && ns>st) 11in ca2ul in care nodul cu inf x are descendent stang{if(ns>par>inf<ns>inf) ns>par>dr!ns>st;else ns>par>st!ns>st;delete ns;}elseif(ns>st!!+ && ns>dr) 11nodul are descendent drept(simetric fata de else precedent){if(ns>par>inf>ns>inf) ns>par>st!ns>dr;else ns>par>dr!ns>dr;delete ns;}else 11nodul are am4ii descendenti{nod* aux;aux!predecesor(ns);cout<<aux>inf<<endl;ns>inf!aux>inf;if(aux>st)   aux>st>par!aux>par; if(aux>par>inf<aux>inf) aux>par>dr!aux>st; else aux>par>st!aux>st;delete aux;}}void 35.(nod *r){if(r){35.(r>st);cout<<r>inf<<- -;35.(r>dr);}}int main(){nod *rad!+; int x;nod *ns;reare(rad); 11se crea2a nodul initial cout<<'ntrodu val care se va adauga';cin>>x; Adauga(rad,x,rad); cout<<'ntrodu val nodului cautat';cin>>x; ns!auta(rad,x); 3terge(rad); 35.(rad);}
Related Search
Similar documents
View more...
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks