Professional Documents
Culture Documents
Quick Sort
Quick Sort
h>
swap(int *a,int l,int u){
int c = a[l];
a[l] = a[u];
a[u] = c;
}
if((upper<=lower))
return;
int l = lower,u;
u=upper;
while(u>l){
while((a[l+1]<=a[lower])&&(u>l))
l++;
while((a[u]>=a[lower])&&(u>l))
u--;
if(u>l)
{swap(a,l+1,u);l++;u--;}
}
if(a[lower]>=a[l]){
swap(a,lower,l);
}
quickSort(a,lower,l-1);
quickSort(a,l+1,upper);
}
for(i=0;i<=j;i++)
printf("%d ",a[i]);
return 0;
}