以快速排序显示每次迭代中的每个元素 [英] Displaying each element in each iteration in quick sort

查看:114
本文介绍了以快速排序显示每次迭代中的每个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我吗?

i想要显示每次迭代中输入的每个元素。

例如输入是59 99 45 79 17 13 49 84

迭代1: - 59 99 45 13 17 79 49 84

迭代2: - 。 。 。 。 。 。 。

迭代3: - 。 。 。 。 。 ..等等

这意味着在每次迭代中显示每个元素

i尝试了很多,但无法获得所需的输出。

can有人帮我吗?

提前多多谢谢



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

推荐答案

您需要在输出所有元素的每个排序步骤中编写一个循环。
You need to write a loop at each sort step that outputs all the elements.


这篇关于以快速排序显示每次迭代中的每个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆