In quick sort,the execution gets stuck after 2, 9 Can someone please tell what is the issue here In quick sort,the execution gets stuck after 2, 9 Can someone please tell what is the issue here In quick sort,the execution gets stuck after 2, 9 Can someone please tell what is the issue here In quick sort,the execution gets stuck after 2, 9 Can someone please tell what is the issue here
#include <stdio.h>
#include <stdlib.h>
int partition (int a[],int start,int end)
{
int i=start;
int j=end;
int temp;
int pivot = a[end];
while( i< j)
{
if(a[i] < pivot && a[j] > pivot)
{
i++;
j--;
continue;
}
else if (a[j] < pivot && a[i] > pivot)
{
temp = a[j];
a[j] = a[i];
a[i] = temp;
i++;
j--;
continue;
}
else if(a[j] < pivot)
{
i++;
continue;
}
if(a[i] > pivot )
{
j--;
continue;
}
}
a[end] = a[i];
a[i] = pivot;
return i;
}
void quicksort(int a[], int s,int e)
{
int k;
printf("entered quicksort- s and e are %d %d\n ",s ,e );
if(s<e){
k = partition(a,s,e);
quicksort(a,s,k-1);
quicksort(a,k+1,e);}
}
int main()
{
int n = 10,i;
int a[10] = {45,78,23,90,80,10,35,37,54,22};
quicksort(a,0,9);
for (i=0; i< n;i++)
{
printf("array is %d ",a[i]);
}
return 0;
}
``````
output is
entered quicksort- s and e are 0 9
entered quicksort- s and e are 0 0
entered quicksort- s and e are 2 9
the execution gets stuck here