Cod sursa(job #2221178)

Utilizator MDiana15Diana M MDiana15 Data 13 iulie 2018 13:21:47
Problema Sortare prin comparare Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <fstream>

using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int n,v[500001],i;
void quicksort(int x,int y)
{
    int i,j,mij;
    i=x;
    j=y;
    mij=(x+y)/2;
     while(i<=j)
    {
        while(v[i]<v[mij])i++;
        while(v[j]>v[mij])j--;
        if(i<=j){swap(v[i],v[j]);
        i++;
        j--;}
    }
    if(x<j)quicksort(x,j);
    if(y>i)quicksort(i,y);
}
int main()
{
    f>>n;
    for(i=1; i<=n; i++)f>>v[i];
    quicksort(1,n);
    for(i=1; i<=n; i++)g<<v[i]<<" ";
    return 0;
}