13,086,662 members (55,871 online)
Rate this:
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?

```// 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```
Posted 13-Dec-12 5:51am
Updated 13-Dec-12 6:01am
Jochen Arndt194.1K
v3
Member 8536324 13-Dec-12 12:27pm

Thank u
Member 8536324 13-Dec-12 12:31pm

sir i also have same problem with merge sort and shell sort can u just take a look at this code and tell me where can i make a change to get the desired output?

Member 8536324 13-Dec-12 12:33pm

// Logic for shell sort\
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

Rate this:

## Solution 1

You need to write a loop at each sort step that outputs all the elements.
Member 8536324 14-Dec-12 4:11am

and sir what about the merge sort?
Member 8536324 14-Dec-12 4:12am

i tried to display elements i got the result but that was not enough
Member 8536324 14-Dec-12 4:12am

thank you sir i got the answer for quick sort

Top Experts
Last 24hrsThis month
 Jochen Arndt 190 Graeme_Grant 180 RyanDev 140 Karthik Bangalore 130 TheRealSteveJudge 95
 OriginalGriff 3,105 Graeme_Grant 1,529 ProgramFOX 1,367 Jochen Arndt 1,270 ppolymorphe 1,227