我遇到了450行程序上堆棧溢出擴展的問題,我需要幫助來優化它。資源密集型程序上的堆棧溢出擴展
該錯誤大多出現在void datacheck()
,它調用了一個無限循環 - 不是因爲它可以完成條件,它只是最難的事情。
我真正的新的編碼,並沒有看到任何改善的餘地。
如果你有經驗,並可以幫助我優化它將意味着我的世界。多謝你們!
int mincount;
int maxcount;
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
int j;
int k;
int l;
int m;
int n;
int o;
int p;
int q;
int r;
int s;
int t;
int u;
int v;
int w;
int x;
int y;
int z;
void MinMax()
{
mincount = Convert.ToInt32(Min_Count.Text);
mincount = int.Parse(Min_Count.Text);
maxcount = Convert.ToInt32(Max_Count.Text);
maxcount = int.Parse(Max_Count.Text);
int a = mincount;
int b = mincount;
int c = mincount;
int d = mincount;
int e = mincount;
int f = mincount;
int g = mincount;
int h = mincount;
int i = mincount;
}
void datacheck(){
if (a == b)
{
a++; datacheck();
}
if (a == c)
{
a++; datacheck();
}
if (a == d)
{
a++; datacheck();
}
if (a == e)
{
a++; datacheck();
}
if (a == f)
{
a++; datacheck();
}
if (a == g)
{
a++; datacheck();
}
if (a == h)
{
a++; datacheck();
}
if (a == i)
{
a++; datacheck();
}
if (b == c)
{
b++; datacheck();
}
if (b == d)
{
b++; datacheck();
}
if (b == e)
{
b++; datacheck();
}
if (b == f)
{
b++; datacheck();
}
if (b == g)
{
b++; datacheck();
}
if (b == h)
{
b++; datacheck();
}
if (b == i)
{
b++; datacheck();
}
if (c == d)
{
c++; datacheck();
}
if (c == e)
{
c++; datacheck();
}
if (c == f)
{
c++; datacheck();
}
if (c == g)
{
c++; datacheck();
}
if (c == h)
{
c++; datacheck();
}
if (c == i)
{
c++; datacheck();
}
if (d == e)
{
d++; datacheck();
}
if (d == f)
{
d++; datacheck();
}
if (d == g)
{
d++; datacheck();
}
if (d == h)
{
d++; datacheck();
}
if (d == i)
{
d++; datacheck();
}
if (e == f)
{
e++; datacheck();
}
if (e == g)
{
e++; datacheck();
}
if (e == h)
{
e++; datacheck();
}
if (e == i)
{
e++; datacheck();
}
if (f == g)
{
f++; datacheck();
}
if (f == h)
{
f++; datacheck();
}
if (f == i)
{
f++; datacheck();
}
if (g == h)
{
g++; datacheck();
}
if (g == i)
{
g++; datacheck();
}
if (h == i)
{
h++; datacheck();
}
newdata();
}
void newdata()
{
j = a * a;
k = b * b;
l = c * c;
m = d * d;
n = e * e;
o = f * f;
p = g * g;
q = h * h;
r = i * i;
totals();
}
void totals() {
s = j + k + l;
t = m + n + o;
u = p + q + r;
v = j + m + p;
w = k + n + q;
x = l + o + r;
y = j + n + r;
z = p + n + l;
check();
}
void check()
{
if (j != k)
{
plusone();
}
else
{
if (k != l)
{
plusone();
}
else
{
if (l != m)
{
plusone();
}
else
{
if (m != n)
{
plusone();
}
else
{
if (n != o)
{
plusone();
}
else
{
if (o != p)
{
plusone();
}
else
{
if (p != q)
{
plusone();
}
else
{
if (q != r)
{
plusone();
}
else { Eureka.Checked = true; }
}
}
}
}
}
}
}
void plusone()
{
if (a < maxcount)
{
a++; checkb();
string sa = a.ToString();
valA.Text = (sa);
}
else { a = mincount; b++; checkb(); }
}
void checkb()
{
if (b < maxcount)
{
string sb = b.ToString();
valC.Text = (sb); checkc();
}
else
{
b = mincount; c++; checkc();
}
}
void checkc()
{
if (c < maxcount)
{
string sc = c.ToString();
valC.Text = (sc); checkd();
}
else
{
c = mincount; d++; checkd();
}
}
void checkd()
{
if (d < maxcount)
{
string sd = d.ToString();
valC.Text = (sd); checke();
}
else
{
d = mincount; e++; checke();
}
}
void checke()
{
if (e < maxcount)
{
string se = e.ToString();
valC.Text = (se); checkf();
}
else
{
e = mincount; f++; checkf();
}
}
void checkf()
{
if (f < maxcount) {
string sf = f.ToString();
valC.Text = (sf); checkg();
}
else { f = mincount; g++; checkg(); }
}
void checkg()
{
if (g < maxcount)
{
string sg = g.ToString();
valC.Text = (sg); checkh();
}
else
{
g = mincount; h++; checkh();
}
}
void checkh()
{
if (h < maxcount)
{
string sh = h.ToString();
valC.Text = (sh); checki();
}
else
{
h = mincount; i++; checki();
}
}
void checki()
{
if (i < maxcount) {
string si = i.ToString();
valC.Text = (si); datacheck();
}
else { NotHere.Checked = true; NotHere.Text = "FUCK"; }
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Start_Click(object sender, EventArgs e)
{
datacheck();
Start.Text = "Restart";
}
這是一個漫長的閱讀
你使用過數組嗎? –
請按照您的代碼。第一次,'a == b',所以'a ++'(現在a = 2),然後再''datacheck''。然後下一個檢查通過:'a == c'。所以現在'b ++'(現在是a和b = 2)和'datacheck'。再次,'a == b'。這會發生,直到你的值溢出;但在此之前;你會得到你的堆棧溢出異常。它難以置信地很難弄清楚該程序應該做什麼 - 但這是*爲什麼*它失敗了。 – Rob
我不知道這個應用程序應該做什麼,我肯定它可以做得更簡單:) – Dennisch