Please look the code below
#include<stdio.h>
void quicksort(int *,int ,int);
int partition1(int *,int ,int);
void swap1(int *,int *);
int main()
{
int low = 0;
int length;
int i;
int a[100];
int high;
printf("Enter the length of array\n");
scanf("%d",&length);
high=length-1;
printf("Enter the array elememts\n");
for(i=0;i<=high;i++)
{
scanf("%d",&a[i]);
}
quicksort(a,low,high);
printf("The sorted array\n");
for(i=low;i<=high;i++)
{
printf("%d--",a[i]);
}
printf("\n");
return 0;
}
void quicksort(int a[],int low,int high)
{
int p;
if(low<high)
{
p=partition1(a,low,high);
quicksort(a,low,p-1);
quicksort(a,p+1,high);
}
}
int partition1(int a[],int low,int high)
{
int pivot=a[high];
int i=low-1;
int j=low;
for(j=low;j<high;j++)
{
if(a[j]<a[high])
{
i++;
swap1(&a[i],&a[j]);
}
}
swap1(&a[i+1],&a[high]);
return i+1;
}
void swap1(int* a,int* b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
This is the working program of quick sort.Can anyone tell me the way to make this program much better?
please do the necessary changes required.