#include<stdio.h>
#include<conio.h>
int c=0;
void quick(int a[],int lb,int ub);
void main()
{
int lb,ub,a[10],i;
clrscr();
printf("enter the lower bound of array");
scanf("%d",&lb);
printf("enter the upper bound bound of array");
scanf("%d",&ub);
printf("\nenter the elements in the list");
for(i=lb;i<=ub;i++)
scanf("%d",&a[i]);
quick(a,lb,ub);
printf("the sorted list is ");
for(i=lb;i<=ub;i++)
printf("\t%d",a[i]);
printf("\nthe complexity of quick sort is =%d",c);
getch();
}
void quick(int a[10],int lb,int ub)
{
int i=lb,j=ub,key=a[lb],temp=0;
if(lb>=ub)
return;
while(i<j)
{
while((key>=a[i])&&(i<j))
i++;
while(key<a[j])
j--;
c++;
if(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
a[lb]=a[j];
a[j]=key;
quick(a,lb,j);
quick(a,j+1,ub);
}