Cod sursa(job #2606757)

Utilizator bem.andreiIceman bem.andrei Data 28 aprilie 2020 15:28:32
Problema Sortare prin comparare Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <iostream>
#include <bits/stdc++.h>

using namespace std;
ifstream r("algsort.in");
ofstream w("algsort.out");
int v[500003];
void quicksort(int inf, int sup)
{
    int x, i, j, t;
    i = inf;
    j = sup;
    x = v[(i + j) / 2];
    do
    {
        while ( (i < sup) && (v[i] < x) )
        {
            i++;
        }
        while ( (j > inf) && (v[j] > x) )
        {
            j--;
        }
        if ( i <= j )
        {
            t = v[i];
            v[i] = v[j];
            v[j] = t;
            i++;
            j--;
        }
    }
    while ( i <= j );
    if ( inf < j )
    {
        quicksort(inf, j);
    }
    if ( i < sup )
    {
        quicksort(i, sup);
    }
}
int main()
{
    int n;
    r>>n;
    for(int i=0; i<n; i++)
    {
        r>>v[i];
    }
    quicksort(0, n-1);
    for(int i=0; i<n; i++)
    {
        w<<v[i]<<" ";
    }
    return 0;
}