Pagini recente » Rating Botnari Daniel (BotnariD) | Profil aaaaaaaadd | Profil Cristi01052 | Cod sursa (job #2001949)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("algsort.in");
ofstream fout("algsort.out");
int v[500000];
int main()
{
int n, i, j = 0, x;
fin >> n;
for(i = 0; i<n; i++)fin >> v[i];
while(j < n)
{
x = j;
for(i = j+1; i<n; i++)
{
if(v[x] > v[i])
{
x = i;
}
}
if(x!=j)
{
v[x] = v[x] + v[j];
v[j] = v[x] - v[j];
v[x] = v[x] - v[j];
}
j++;
}
for(i = 0; i<n; i++)fout << v[i] << ' ';
return 0;
}