Click here to Skip to main content
12,508,014 members (46,092 online)
Rate this:
 
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 5:51am
Updated 13-Dec-12 6:01am
Jochen Arndt142.8K
v3
Comments
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

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 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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160927.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2016
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