This program is supposed to impelement quicksort but it is not working
Code:
include<stdio.h>
#include<conio.h>
#include<process.h>
void quicksort(int a[] ,int low,int high);
int partition(int a[] , int low,int high);
//quick sort
void main()
{
int a[10], n ,i;
clrscr();
printf("enter the total no. of elements \n");
scanf("%d",&n);
printf("enter the elements of the array \n");
for(i=0;i<n;i++){
scanf("%d",&a[i]);}
quicksort(a,0,n-1);
printf("sorted array is \n");
for(i=0;i<n;i++)
printf("%d",a[i]);
getch();
}
void quicksort(int a[] ,int low,int high)
{
int mid ;
if (low<high)
{
mid=partition(a,low,high);
quicksort(a,low,mid-1);// partioned elemnt in its final position at mid
quicksort(a,mid+1,high);
}
}
partition(int a[], int low,int high)
{
int temp,i,pivot,j;
i=low;
j=high;
pivot=a[i];
while (i<=j)
{
while(a[i]<=pivot && i<=high){i=i+1;}
while(a[j]>pivot){j=j-1;}
if(i<j){
temp=a[i];
a[j]=a[i];
a[j]=temp;
}
temp=pivot;
pivot=a[j];
a[j]=temp;
}
return j;
}