本文介绍了排序数组的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我是这个论坛的新手,也刚刚开始使用c#,我正在尝试编写一些程序,您可以动态分配存储在数组中的按钮,每次点击一个按钮,它会显示一个按钮的编号一个标签。我还需要更新点击按钮的频率,最后根据一个按钮对它们进行排序,从最小到最大。所以我不能使用排序方法我只能使用嵌套for循环。

这是我的代码到目前为止,每次点击按钮进行排序它只给我一个数字?

谢谢



lstNum是一些分配的按钮,freqArray是一个按钮数组,而lbl.Out.Digits是标签,其中出现点击按钮的数量在那里我需要显示点击按钮的排序列表。



int temp = 0;

for(int i = 0; i< ; lastNum; i ++)

{

for(int j = i + 1; j< lastNum; j ++)

{

if(freqArray [i]> freqArray [j])

{

temp = freqArray [i];

freqArray [i] = freqArray [j];

freqArray [j] = temp;

}



}



lblOutDigits.Text = freqArray [i] .ToString();

}

解决方案



Hi I am new on this forum and also just started with c#, I am trying to write some program where you have dynamically allocated buttons stored in an array and every time u click on a button it show you number of a button in a label. also I needed to update the frequency of clicked buttons and at the end to sort them from smallest to largest buy clicking on one button. So I cant use sort method I only can use nested for loops.
This is my code so far and every time I click on button for sorting it gives me only one number??
Thank you

lstNum is a number of allocated buttons and freqArray is an array of buttons, and lbl.Out.Digits is label where number of clicked button appear and there I need to display sorted list of clicked buttons.

int temp = 0;
for (int i = 0; i < lastNum; i++)
{
for (int j = i + 1; j < lastNum; j++)
{
if (freqArray[i] > freqArray[j])
{
temp = freqArray[i];
freqArray[i] = freqArray[j];
freqArray[j] = temp;
}

}

lblOutDigits.Text = freqArray[i].ToString();
}

解决方案



这篇关于排序数组的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 16:37