Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //functie sa ordoneze crescator elemente dintr o lista simpla inlantuita cu nr intregi
- struct nod
- {
- int info;
- nod *urm;
- };
- nod *c, *p, *u;
- int i, n;
- void creare()
- {
- cout<<"Numarul de elemente ";
- cin>>n;
- c=new nod;
- cout<<"Informatia ";
- cin>>c->info;
- p=c;
- u=c;
- c->urm=NULL;
- for(i=2; i<=n; i++)
- {
- c=new nod;
- cout<<"Informatia ";
- cin>>c->info;
- u->urm=c;
- c->urm=NULL;
- u=c;
- }
- }
- void afisare()
- {
- c=p;
- cout<<endl<<"Lista este ";
- while(c)
- {
- cout<<c->info<<" ";
- c=c->urm;
- }
- }
- void ordonare()
- {
- int aux;
- c=p;
- while(c->urm!=NULL)
- {
- if(c->info >= c->urm->info)
- {
- aux=c->info;
- c->urm->info=c->info;
- c->info=aux;
- }
- c=c->urm;
- }
- }
- int main()
- {
- creare();
- afisare();
- ordonare();
- afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement