Hi,
I am sorry to tell you, but the segmentation fault probably comes from the many, many errors in your code. I got a stack overflow when I tried the code, but let's go through it.
Your main procedure is okay, but should look more like this:
void main()
{
int a[MAX], n, i; clock_t end, start;
for(i=0;i<n;++i) scanf("%d",&a[i]);
for(i=0;i<n;++i) printf("%d\t",a[i]);
}
The quick_sort procedure is okay and seriously, I don't want to sound cocky or something, but the partition function is kinda messed up. Let's see:
int partition(int a[],int low,int high)
{
int i,j,temp,key;
key=a[(low+high)/2];
i=low;
j=high;
while (i < j)
{
while (a[i] < key) ++i;
while (key < a[j]) --j;
if (i < j) temp = a[i], a[i] = a[j], a[j] = temp;
}
return i;
}
I suggest to analyze every state change when you develop an algorithm like this. I used a piece of paper for that and wrote down the variables used in loops for every iteration. This helps to find inconsistencies in your algorithms pretty quickly and often, you also get an idea on how to solve them that way, too.
I hope, I could help you with this.
Cheers!