fork download
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5.  
  6. const int N=25;
  7. int tab[N];
  8.  
  9. void losuj(int a, int b)
  10. {
  11. srand(time(NULL));
  12. for (int i=0; i<N; i++)
  13. tab[i] = rand()%(b-a+1)+a;
  14.  
  15. }
  16.  
  17. void wypisz()
  18. {
  19. for (int i=0; i<N; i++)
  20. cout << tab[i] << " ";
  21. cout << endl;
  22. }
  23.  
  24.  
  25. void sort_b()
  26. {
  27. for(int i=0; i< N-1; i++)
  28. {
  29. for (int j=0; j<N-1; j++)
  30. {
  31. if (tab[j]<tab[j+1])
  32. swap(tab[j],tab[j+1]);
  33. }
  34. }
  35. }
  36.  
  37.  
  38. void sort_w()
  39. {
  40. int pom, j;
  41. for (int i=1;i<N;i++)
  42. {
  43. pom=tab[i];
  44. j=i-1;
  45. while (j>=0 && pom<tab[j])
  46. {
  47. tab[j+1]=tab[j];
  48. j--;
  49. }
  50. tab[j+1]=pom;
  51. }
  52. }
  53.  
  54.  
  55. int main() {
  56.  
  57. losuj(-10,100);
  58. cout << "Przed sortowaniem: " << endl;
  59. wypisz();
  60. //sort_b();
  61. sort_w();
  62. cout << "Po posortowaniu: " << endl;
  63. wypisz();
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0s 5328KB
stdin
Standard input is empty
stdout
Przed sortowaniem: 
57 63 57 42 32 99 -9 8 39 64 83 45 39 68 -8 78 45 82 -5 53 79 62 75 13 -8 
Po posortowaniu: 
-9 -8 -8 -5 8 13 32 39 39 42 45 45 53 57 57 62 63 64 68 75 78 79 82 83 99