简体   繁体   English

我想在gui中的c#中逐步排序

[英]I want to sorting step by in c# in gui

I have wrote this code for c# 我已经为C#编写了这段代码

void SelectionSort()
    {
        clearFontColor();
        int i, j, min, temp;
        for (i = 0; i < 9; i++)
        {
            min = i;
            for (j = i + 1; j < 10; j++)
            {
                if (input[min] > input[j])
                {
                    min = j;
                }
            }
            if (min != i)
            {
                temp = input[i];
                input[i] = input[min];
                input[min] = temp;
            }

        }
         show(input);
    }

But this is doing only one step and later it stops.How to achieve that. 但这只是一步而已,后来又停止了。

The button for sort action is like 排序操作的按钮就像

  private void button2_Click(object sender, EventArgs e)
    {
        // lbl_step.Visible = true;
        if (radioButton2.Checked)
        {
            InsertionSort();
        }
        else if (radioButton1.Checked)
        {
            bubble();
        }
        else if (radioButton3.Checked)
        {
            SelectionSort();
        }

    }  

and its working for just one time after that it stops working. 并且它在停止工作后仅工作了一次。

Assuming your code is correct you have do something like this. 假设您的代码是正确的,您可以执行以下操作。 So your code will run through and show the change howevever, this is happening so faster you won't see it on the GUI. 因此,您的代码将一直运行并显示更改,这种更改发生得如此之快,以至于您不会在GUI上看到它。 You need to make variables ia class member. 您需要使变量成为类成员。 Then in your button click, you increment i. 然后在您的按钮中单击,增加i。

So the summary: Set i to a number each button click. 总结一下:将i设置为每个按钮单击的数字。 Then your method will only do one iteration and show the user interface. 然后,您的方法将只执行一次迭代并显示用户界面。 To continue you click the button again and increment i (make sure to check bounds). 要继续操作,请再次单击该按钮并增加i(确保检查范围)。

int i;
void SelectionSort()
{
    clearFontColor();
    int j, temp;
    min = i;
    for (j = i + 1; j < 10; j++)
    {
        if (input[min] > input[j])
        {
            min = j;
        }
    }
    if (min != i)
    {
        temp = input[i];
        input[i] = input[min];
        input[min] = temp;
    }
    show(input);
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM