按名称排序(按字母顺序) [英] Sorting by Name (alphabetic)

查看:124
本文介绍了按名称排序(按字母顺序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数组的小应用程序。一个阵列是名字,一个阵列是分数。我有一个排序按钮,下面的代码。此外,还有6单选按钮排序不同的方式。这些按钮的5工作,但我似乎无法通过区域名称的工作得到了排序。有时,当我进入两行到它的工作阵列,有时没有。我一直在试图弄清楚这一点了近一个小时,但似乎无法弄清楚,为什么它不会工作。任何想法了吗?



 私人无效btnSort_Click(对象发件人,EventArgs五)
{
INTñ ;
十进制温度;
INT sortCol = 0;
串NTEMP;
布尔swapFlag;


如果(rb1.Checked)
sortCol = 0;

如果(rb2.Checked)
sortCol = 1;

如果(rb3.Checked)
sortCol = 2;

如果(rb4.Checked)
sortCol = 3;

如果(rbTotal.Checked)
sortCol = 4;


{
swapFlag = FALSE;
为(N = 0; N< lastIndexUsed; N ++)
{
如果(宿舍[N,sortCol] LT;宿舍[N + 1,sortCol])
{

//第4列
TEMP =宿舍[N,4];
宿舍[N,4] =季度[n + 1个,4〕;
季度[n + 1个,4] =温度;

//第3栏第
TEMP =宿舍[N,3];
宿舍[N,3] =季度[n + 1个,3];
季度[n + 1个,3] =温度;

//第2栏

TEMP =宿舍[N,2];
宿舍[N,2] =季度[n + 1个,2];
季度[n + 1个,2] =温度;

//山坳1
TEMP =宿舍[N,1];
宿舍[N,1] =季度[n + 1个,1];
季度[n + 1个,1] =温度;

//山坳0
TEMP =宿舍[N,0];
宿舍[N,0] =季度[n + 1个,0];
季度[n + 1个,0] =温度;

//名

= NTEMP科[N];
科[N] =科[N + 1];
科[N + 1] = NTEMP;

swapFlag = TRUE;

} // ENDIF

} //最终

},而(swapFlag);


解决方案

在黑暗中拍摄:你说你有六个单选按钮,但你只检查五个由分配排序列。如果你的各种各样的五个工作和一个心不是,也许这就是你省去了按钮?



这很难说,如果这真的是问题。这些字段的名称非常清楚 - 在你心目中是单选按钮6或按钮按区域名称排序?名称的东西什么的表示


I have a small application with two arrays. One array is the names, one array is the scores. I have the below code in a "sort" button. There are also 6 radio buttons that sort by different ways. 5 of these buttons work, but I cannot seem to get the sort by "Region Name" working. Sometimes when I enter two rows into the arrays it works, sometimes not. I have been trying to figure this out for nearly an hour but cannot seem to figure out why it will not work. Any ideas out there?

private void btnSort_Click(object sender, EventArgs e)
        {
            int n;
            decimal temp;
            int sortCol = 0;
            string ntemp;
            bool swapFlag;


            if (rb1.Checked)
                sortCol = 0;

            if (rb2.Checked)
                sortCol = 1;

            if (rb3.Checked)
                sortCol = 2;

            if (rb4.Checked)
                sortCol = 3;

            if (rbTotal.Checked)
                sortCol = 4;

            do
            {
                swapFlag = false;
                for (n = 0; n < lastIndexUsed; n++)
                {
                    if(quarters[n,sortCol] < quarters[n+1, sortCol])
                        {

                        //column 4
                            temp = quarters[n, 4];
                            quarters[n, 4] = quarters[n + 1, 4];
                            quarters[n+1, 4] = temp; 

                        //col 3
                            temp = quarters[n, 3];
                            quarters[n, 3] = quarters[n + 1, 3];
                            quarters[n + 1, 3] = temp; 

                        //col 2

                            temp = quarters[n, 2];
                            quarters[n, 2] = quarters[n + 1, 2];
                            quarters[n + 1, 2] = temp;

                        // col 1
                            temp = quarters[n, 1];
                            quarters[n, 1] = quarters[n + 1, 1];
                            quarters[n + 1, 1] = temp;

                        //col 0
                            temp = quarters[n, 0];
                            quarters[n, 0] = quarters[n + 1, 0];
                            quarters[n + 1, 0] = temp;

                        //name

                            ntemp = Branch[n];
                            Branch[n] = Branch[n + 1];
                            Branch[n + 1] = ntemp;

                            swapFlag = true;

                        }//endif

                }//for end

            } while (swapFlag);

解决方案

A shot in the dark: You say you have six radio buttons, but you're only checking five and assigning the sort column by that. If five of your sorts are working and one isnt, maybe that's the button you omitted?

It is difficult to tell if this really the problem. The names of those fields are very unclear - in your mind is it "radio button 6" or "the button to sort by region name"? Name something for what it means.

这篇关于按名称排序(按字母顺序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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