#include<stdio.h>
long arr[1000001];
quicksort(long,long);
partition(long,long);
main()
{
long T=0,i=0,temp=0,j=0;
scanf("%ld",&T);
while(i<T)
{
scanf("%ld",&arr[i]);
i++;
}
quicksort(0,T-1);
i=0;
while(i<T)
{
printf("%ld\n",arr[i]);
i++;
}
}
quicksort(long start,long end)
{
long pindex;
if(start<end)
{
pindex = partition(start,end);
quicksort(start,pindex-1);
quicksort(pindex+1,end);
}
}
partition(long start,long end)
{
long i ,pivot , pindex,temp;
pivot = end;
pindex = start;
i=start;
while(i<end)
{
if(arr[i]<=arr[pivot])
{
temp = arr[i];
arr[i] = arr[pindex] ;
arr[pindex] = temp;
pindex = pindex +1;
}
i++;
}
temp = arr[pivot];
arr[pivot] = arr[pindex];
arr[pindex] = temp;
return(pindex);
}
Comments
Guys i’m here trying “Quick Sort” O(nlogn) and i guess this is good sorting technique and among one of the fastest and still im getting time limit error … Plz if any of you guys can help me in optimizing so that i can decrease Execution and compilation time
i tried fast IO but was not able to understand its code and it didnt work for me.