13,086,662 members (55,871 online)

Email

Password

Sign in with

See more:

Can anyone help me?

i want to display each element that were entered for sorting in each iteration.

for e.g if input is 59 99 45 79 17 13 49 84

Iteration 1:- 59 99 45 13 17 79 49 84

Iteration 2:- . . . . . . .

Iteration 3:- . . . . . .. etc.

that means displaying each element in each iteration

i tried a lot but can't get the desired output.

can anyone help me?

thanks a lot in advance

i want to display each element that were entered for sorting in each iteration.

for e.g if input is 59 99 45 79 17 13 49 84

Iteration 1:- 59 99 45 13 17 79 49 84

Iteration 2:- . . . . . . .

Iteration 3:- . . . . . .. etc.

that means displaying each element in each iteration

i tried a lot but can't get the desired output.

can anyone help me?

thanks a lot in advance

```
// Logic for quick sort
void quick(int *a,int left,int right)
{
int i,j,key,t,k;
if(left<right) //check when the element is only one
{
i=left;
j=right+1;
key=a[left];
while(i<j)
{
printf("Iteration-%d : ",c);
c=c+1;
for(k=0;k<right+1;k++)
{
printf("%d ",a[k]);
}
printf("\n");
i++;
while(a[i]<key)
i++;
j--;
while(a[j]>key)
j--;
if(i<j)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
t=a[left];
a[left]=a[j];
a[j]=t;
quick(a,left,j-1);
quick(a,j+1,right);
}
textcolor(7);
} // quick() ends here
```

Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada
+1 416-849-8900 x 100

void shell(int *a,int n,int *span,int ni)

{

int i,j,k,s,t,b;

c=0;

for(k=0;k<n;k++)

{

s=span[k];

printf("Iteration-%d : ",c+1);

c++;

for(b=0;b<n;b++)

{

printf("%d ",a[b]);

}

printf("\n");

for(i=1;i<n;i++)

{

t=a[i];

for(j=i-s;j>=0 && t<a[j];j=j-s)

{

a[j+s]=a[j];

}

a[j+s]=t;

}

}

textcolor(7);

} // shell() ends here