Greetings All,
I am trying to write a program for sorting number by quick sort method.
I am posting the Code, There is no Compiler error but the result is wrong.
can anyone please point me out the mistake.
Thank you in Advance.
Code:
#include <Stdio.h>
#include <conio.h>
int sorted(int *l, int *u)
{
int mark;
while(l<=u)
{
if((*l)<(*(l+1)))
mark=1;
else
return 0;
l++;
}
return 1;
}
void quick(int *a, int *b)
{
int hold,s;
int *ll=(a+1);
int *ul=b;
for(;ll<=ul;ll++,ul--)
{
if((*ll>*a)&&(*ul<*a))
{
hold=*ul;
*ul=*ll;
*ll=hold;
}
}
*a=*ll;
*ll=hold;
s=sorted(a,b);
if(s==0)
{
quick(a,ll-1);
quick(ll+1,b);
}
}
int main()
{
int *a;
int *b;
int arr[50];
int n,count;
clrscr();
printf("Entre the length of the Array to be sorted");
scanf("%d",&n);
printf("Entre the Array");
for(count=0;count<n;count++)
{
scanf("%d",arr[count]);
}
a=&(arr[0]);
b=&(arr[n-1]);
quick(a,b);
printf("The sorted Array is");
for(count=0;count<n;count++)
{
printf("%d",arr[count]);
}
getch();
return 0;
}