Odpowiedź:
#include<iostream>
int main() {
int tab[] = {-11, 12, 3, 5, 21, -53, 17};
const int length = 7;
for (int i = 0; i < length; i++) {
std::cout << "Mamy nastepujace liczby\n";
for(int j = 0; j < length; j++){
std::cout << tab[j] << " ";
}
std::cout << std::endl;
for (int j = 0; j < length - 1 - i; j++) {
if (tab[j] < tab[j + 1]) {
std::cout << "Zamieniamy " << tab[j] << " z " << tab[j + 1] << std::endl;
int temp;
temp = tab[j + 1];
tab[j + 1] = tab[j];
tab[j] = temp;
}
}
std::cout << std::endl;
}
std::cout << "Wyświetlenie posortowanych:\n ";
for (int i = 0; i < length; i++) {
std::cout << tab[i] << std::endl;
}
return 0;
}
Wyjaśnienie:
Uruchom sobie ten program, on wypisuje sam co i jak się dzieje. Szybciej zeszło program napisać niż samemu to rozrysować xd