Cod sursa(job #1982034)

Utilizator tothalToth Alexandru tothal Data 17 mai 2017 16:38:12
Problema Sortare prin comparare Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <fstream>

using namespace std;
ifstream fin("algsort.in");
ofstream fout("algsort.out");

int n, v[500005];

void read()
{
    fin >> n;
    for( int i = 0; i < n; i++)
        fin >> v[i];
}
void bubblesort()
{
    for(int i = 0; i < n-1; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            if( v[j] < v[i])
                swap(v[i],v[j]);
        }
    }
}
void write()
{
    for(int i = 0; i < n; i++)
        fout << v[i] << " ";
    fout << endl;
}
int main()
{
    read();
    //write();
    bubblesort();
    write();
fin.close();
fout.close();
}