Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
85
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. c=p;
  51. while(c->urm!=NULL)
  52. {
  53. if(c->info > c->urm->info)
  54. {
  55. aux=c->urm->info;
  56. c->urm->info=c->info;
  57. c->info=aux;
  58. }
  59. c=c->urm;
  60. }
  61.  
  62. }
  63.  
  64. int main()
  65. {
  66. creare();
  67. afisare();
  68. ordonare();
  69. afisare();
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement