这个循环有什么问题? [英] What is wrong with this loop ?

查看:80
本文介绍了这个循环有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个程序来查找中位数,但是运行时该程序崩溃了!!
好的,更具体地说,我必须将此中间值应用到另一个foor循环中,但是当我尝试这样做时,系统就停止了.没有错误信息!!!

I wrote a program to find the median, but the program crashes when I run!!
Okay, to be more specific, I have to apply this median value in another foor loop, but when I try to do that, the system just stops. No error message!!!

for (int b = 0;b < size; b++)
    {
        for (int i = 0; i < size; ++i)
        {
            dpSorted[i] = myData[i]; // This is an array already present
        }
        for (int i = pCurRec->m_size - 1; i > 0; --i)
        {
            for (int j = 0; j < i; ++j)
            {
                if (dpSorted[j] >dpSorted[j+1])
                {
                    double dTemp = dpSorted[j];
                    dpSorted[j] = dpSorted[j+1];
                    dpSorted[j+1] = dTemp;
                }
            }
        }
        if ((pCurRec->m_size % 2) == 0)
        {
            dMedian[b] =  (dpSorted[size/2] + dpSorted[(size/2) - 1])/2.0;
        }
        else
        {
            dMedian[b] = dpSorted[size/2];
        }
    }

推荐答案

第六行[j + 1]超出了大小限制.
Sixth line [j+1] goes beyond size limit.


Ganesan为您找到了一个问题,但提出这样的问题是毫无意义的.请不要. 相反,请在调试器下运行代码!它将告诉您所有信息.并且仅当即使使用调试器仍无法解决问题时,也要提一个问题,但要提供足够的异常信息,并指出引发,处理,传播异常的行号.

—SA
Ganesan found one problem for you, but asking such questions is quite pointless. Please don''t. Instead, run your code under debugger! It will tell you everything. And only when you fail to resolve the problem even with the debugger, ask a question, but provide sufficient exception information, and indicate the line numbers where exception is thrown, handled, propagated, etc.

—SA


这篇关于这个循环有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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