fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // zamiana miejscami
  5. void babelek(int &a, int &b) {
  6. int temp = a;
  7. a = b;
  8. b = temp;
  9. }
  10.  
  11. // wypisywanie tablicy
  12. void wypisz(int tab[], int n) {
  13. for (int i = 0; i < n; i++) {
  14. cout << tab[i] << " ";
  15. }
  16. cout << endl;
  17. }
  18.  
  19. // sortowanie bÄ…belkowe
  20. void sort_b(int tab[], int n) {
  21. for (int i = 0; i < n - 1; i++) {
  22. for (int j = 0; j < n - 1 - i; j++) {
  23. if (tab[j] > tab[j + 1]) {
  24. babelek(tab[j], tab[j + 1]);
  25. }
  26. }
  27. }
  28. }
  29.  
  30. int main() {
  31. int tab[5] = {6, 3, 15, 9, 2};
  32.  
  33. cout << "Przed: ";
  34. wypisz(tab, 5);
  35.  
  36. sort_b(tab, 5);
  37.  
  38. cout << "Po: ";
  39. wypisz(tab, 5);
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Przed: 6 3 15 9 2 
Po: 2 3 6 9 15