Pagini recente » Cod sursa (job #3125481) | Cod sursa (job #1751859) | Cod sursa (job #3261396) | Cod sursa (job #420982) | Cod sursa (job #3039070)
// Selection Sort - Complexitate O(n^2)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream in("algsort.in");
ofstream out("algsort.out");
const int dim = 500001;
int v[dim];
int main()
{
int n, i, poz_min,j;
in >> n;
for(i = 1; i <= n; i++) {
in >> v[i];
}
// selection sort
for(i = 1; i < n; i++) {
poz_min = i;
for(j = i + 1; j <= n; j++ ) {
if(v[j] < v[poz_min]) {
poz_min = j;
}
}
swap(v[i], v[poz_min]);
}
// afisare vector v
for (i = 1; i <= n; i++) {
out << v[i] << " ";
}
return 0;
}