Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C
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
 
// 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 6:51am
Edited 13-Dec-12 7:01am
v3
Comments
Member 8536324 at 13-Dec-12 12:27pm
   
Thank u
Member 8536324 at 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 at 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=0 && t

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to write a loop at each sort step that outputs all the elements.
  Permalink  
Comments
Member 8536324 at 14-Dec-12 4:11am
   
and sir what about the merge sort?
Member 8536324 at 14-Dec-12 4:12am
   
i tried to display elements i got the result but that was not enough
Member 8536324 at 14-Dec-12 4:12am
   
thank you sir i got the answer for quick sort

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

  Print Answers RSS
0 OriginalGriff 7,355
1 DamithSL 5,199
2 Sergey Alexandrovich Kryukov 4,942
3 Maciej Los 4,906
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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