Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //functie sa ordoneze crescator elemente dintr o lista simpla inlantuita cu nr intregi
  5.  
  6. struct nod
  7. {
  8. int info;
  9. nod *urm;
  10. };
  11. nod *c, *p, *u;
  12.  
  13. int i, n;
  14.  
  15. void creare()
  16. {
  17. cout<<"Numarul de elemente ";
  18. cin>>n;
  19. c=new nod;
  20. cout<<"Informatia ";
  21. cin>>c->info;
  22. p=c;
  23. u=c;
  24. c->urm=NULL;
  25. for(i=2; i<=n; i++)
  26. {
  27. c=new nod;
  28. cout<<"Informatia ";
  29. cin>>c->info;
  30. u->urm=c;
  31. c->urm=NULL;
  32. u=c;
  33. }
  34. }
  35.  
  36. void afisare()
  37. {
  38. c=p;
  39. cout<<endl<<"Lista este ";
  40. while(c)
  41. {
  42. cout<<c->info<<" ";
  43. c=c->urm;
  44. }
  45. }
  46.  
  47. void ordonare()
  48. {
  49. int aux;
  50.  
  51. c=p;
  52. while(c->urm!=NULL)
  53. {
  54.  
  55.  
  56. if(c->info >= c->urm->info)
  57. {
  58. aux=c->info;
  59. c->urm->info=c->info;
  60. c->info=aux;
  61. }
  62. c=c->urm;
  63. }
  64.  
  65. }
  66.  
  67. int main()
  68. {
  69. creare();
  70. afisare();
  71. ordonare();
  72. afisare();
  73.  
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement