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