0

Ok... i ran my quicksort program on my college lab's machine (i dunno its config) and it took 4 seconds on avg to sort 1 million elements. I ran it on my lappy (4 gb RAM, Intel Core i5-2410M Processor (2.3 GHz)) and it took 0.83 seconds to run the same number of elements. So, now I'm a little confused. I'd be really obliged if you could tell me if my quicksort program can be improved and if yes, then how.

Thanks in advance.

```
#include<stdio.h>
void quicksort(int*,int,int);
int n;
int main()
{
scanf("%d",&n);
int i, a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
quicksort(a,0,n-1);
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
void quicksort(int *a, int start, int end)
{
if(start>=end)
return;
int pivot=(start+end)/2;//choosing mid element as pivot
a[pivot]=a[end]+a[pivot]-(a[end]=a[pivot]);//swapping it ith last element
pivot=end;
int hi=start,i;//hi (high index) marks the beginning index of higher elements
for(i=start;i<end;i++)
{
if(a[i]<=a[pivot])
{
a[hi]=a[i]+a[hi]-(a[i]=a[hi]);
hi++;
}
}
a[hi]=a[pivot]+a[hi]-(a[pivot]=a[hi]);
pivot=hi;
hi++;
quicksort(a,start,pivot-1);
quicksort(a,hi,end);
}
```