Cod sursa(job #1282566)

Utilizator thinkphpAdrian Statescu thinkphp Data 4 decembrie 2014 14:56:55
Problema Sortare prin comparare Scor 0
Compilator c Status done
Runda Arhiva educationala Marime 1.2 kb
#include <stdio.h>
#define FIN "algsort.in"
#define FOUT "algsort.out"
#define MAXN 500005

typedef unsigned int uint;

uint arr[ MAXN ],

     n;

void read() {

     uint i;

     freopen(FIN, "r", stdin);

     scanf("%d", &n);

     for(i = 0; i < n; i++) scanf("%d", &arr[ i ]); 

     fclose( stdin );

};

void swap(uint *i, uint *j) {

     uint temp;

     temp = *i;

     *i = *j;

     *j = temp;
};

uint pivot(int low, int high) {

     uint i = low,

          j = high,

          p = arr[ ( low + high ) >> 1 ];

          while(i <= j) {

                while(arr[ i ] < p) i++;

                while(arr[ j ] > p) j--;

                if( i <= j ) swap( &arr[ i++ ], &arr[ j++ ]);
          } 

        if(low < p) pivot(low, p);           

        if(p < high) pivot(p, high);
};

void _qsort(int left, int right) {

     uint p;

          p = pivot(left, right);
}

void qsort() {

     pivot(0, n - 1);
};

void write() {

   uint i;

   freopen(FOUT, "w", stdout);

   for(i = 0; i < n; i++) printf("%d ", arr[ i ]); 

   fclose( stdout );
}

int main() {

    read();

    qsort();

    write();

    return(0);
};