Odpowiedź:
#include <iostream>
using namespace std;
int main()
{
int N;
cin >> N;
int d[N],i,p,pmin,pmax;
for(i = 0; i < N; i++)
cin >> d[i];
}
pmin = 0; pmax = N - 1;
do
p = -1;
for(i = pmin; i < pmax; i++)
if(d[i] > d[i+1])
swap(d[i], d[i+1]);
if(p < 0) pmin = i;
p = i;
if(pmin) pmin--;
pmax = p;
} while(p >= 0);
for(i = 0; i < N; i++) cout << d[i] << ' ';
return 0;
Wyjaśnienie:
np. takie proste sortowanie
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2025 KUDO.TIPS - All rights reserved.
Odpowiedź:
#include <iostream>
using namespace std;
int main()
{
int N;
cin >> N;
int d[N],i,p,pmin,pmax;
for(i = 0; i < N; i++)
{
cin >> d[i];
}
pmin = 0; pmax = N - 1;
do
{
p = -1;
for(i = pmin; i < pmax; i++)
if(d[i] > d[i+1])
{
swap(d[i], d[i+1]);
if(p < 0) pmin = i;
p = i;
}
if(pmin) pmin--;
pmax = p;
} while(p >= 0);
for(i = 0; i < N; i++) cout << d[i] << ' ';
return 0;
}
Wyjaśnienie:
np. takie proste sortowanie