
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#define MAX 100000
void quicksort(int *p,int n,long double *syg)
{
        int a;
if(n>1)
{
        a=partition(p,n,syg);

        quicksort(p,a,syg);

        quicksort(p+a,n-a,syg);
}

return;
}

int partition(int *p,int n, long double *syg)
{
int *p1,*p2,temp;
for(p1=p-1,p2=p+n; ;)
{
        do
        {	++(*syg);
                ++p1;
                
        }while(*p1<*p);

        do
        {	++(*syg);
                --p2;
        	        
        }while(*p2>*p);
        
        if(p1<p2)
        {		
                temp=*p1;
                *p1=*p2;
                *p2=temp;
        } 
        else
                break;
	
}
                
return (int) (p2-p+1);

}
         
int main()

 {
        int *p;
        int i,x,y,n=MAX;
        long double syg=0;
        clock_t t2;
	time_t seed;
	long r;
	p=(int *)malloc(MAX+100000000);
        
	time(&seed);
	srand((long)seed);

        for(i=0;i<MAX;i++)
         {
               r=rand();
	*(p+i)=r;
         }
                
         
         
       /* for(i=0;i<MAX;i++)
        {
                printf("stoixeia pinaka %d\n",*(p+i));

		  }
        */
        
        
        
        clock(); 
        if(p!=NULL)
        {       quicksort(p,n,&syg);    }
          
        t2=clock();
        printf("oi sygriseis poy eginan einai : %.0f\n",fabs(syg));
        printf("xronos poy xreiastike :%d microsecond\n",(t2));
                
    /*     for(i=0;i<MAX;i++)
        {
                printf("stoixeia pinaka %d\n",p[i]);
        }
              */
}