Cod sursa(job #1806706)

Utilizator RadduFMI Dinu Radu Raddu Data 15 noiembrie 2016 17:14:32
Problema Sortare prin comparare Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <iostream>
#include <fstream>

using namespace std;
int a[500005];

ifstream f("algsort.in");
ofstream g("algsort.out");
void Quick(int st,int dr)
{

    int i, p = (st+dr)/2 ,ind = st-1;


   swap(a[p],a[dr]);

   for(i=st;i<=dr;i++)
    if (a[i]<=a[dr])
      { ind++;
        swap(a[ind],a[i]);
      }

   if (ind-1 > st) Quick(st,ind-1);
   if (ind+1 < dr) Quick(ind+1,dr);
}

int main()
{ int n,i;
    f>>n;

    for(i=1;i<=n;i++)
      f>>a[i];



    Quick(1,n);

    for(i=1;i<=n;i++)
     g<<a[i]<<" ";

    return 0;
}