Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- struct nod{
- int info;
- nod *urm;
- } ;
- nod *p,*u,*c;
- int n;
- void adauga(int *&p,int *&u, int x){
- nod * c;
- c = new nod;
- c->info=x;
- if(!p){
- p=new nod;
- p->info=x;
- p->urm=NULL;
- u=p;
- }else{
- c->urm=NULL;
- u->urm=c;
- u=c;
- }
- }
- void afisare(nod *p){
- nod *c;
- cout << endl;
- for(c=p;c!=NULL;c=c->urm){
- cout << c->info << " ";
- }
- }
- void main(){
- cin >> n;
- int i,x,gata=0;
- for(i=0;i<n;i++){
- cin>>x;
- adauga(p,u,x);
- }
- nod *a,*b;
- int mod;
- while(gata==0){
- gata=1;
- mod=1;
- c=p;
- while(c->urm!=NULL){
- if(mod==0) c=c->urm;
- mod=0;
- if(p->urm==c)a=p;
- if(c->info > c->urm->info && c->urm!=NULL){
- if(c==p){
- b=c;
- p=c->urm;
- b->urm=p->urm;
- p->urm=b;
- c=b;
- a=p;
- }else{
- b=c;
- c=c->urm;
- a->urm=c;
- b->urm=c->urm;
- c->urm=b;
- c=b;
- if(c->urm==NULL) u=c;
- a=a->urm;
- }
- gata=0;
- mod=1;
- }else if(c!=p){
- a->urm=c;
- a=a->urm;
- }
- }
- }
- afisare(p);
- }
Add Comment
Please, Sign In to add comment