Partitioning an array by another method

Leave a Comment
#include<conio.h>
#include<sdtio.h>


int main()
{
int a[100],s=0,i,av,j,t,n;
printf("\nEnter the max. limit:");
scanf("%d", &n);
for(i=0;i<n;i++) {
printf("\nEnter the method:");
scanf("%d",&a[i]);
}
for(i=0;i<n;i++) {
s=s+a[i];
}
printf("\nEnter the av value:");
scanf("%d",&av);
i=0;j=n-1;
while(i<n) {
if(a[i]>=av)
{
if(a[j] {
t=a[i];
a[i]=a[j];
a[j]=t;
i++;
j--;
}
else if(a[j]>av)
{
j--;
}
}

else if(a[j] {
if(a[i]>av)
{
t=a[i];
a[i]=a[j];
a[j]=t;
i++;
j--;
}
else if(a[i] {
i++;
}
}
}
printf("\nThe partitioned array along %d is\n\n",av);
for(i=0;i<n;i++) {
printf("%d\t",a[i]);
}
getche();
return 0;
}

0 comments: