我在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";
}
这是一个很长的阅读
答案 0 :(得分:0)
经验教训,将其全部分解为不同的功能,而不是一遍又一遍地重置相同的功能
void datachecka() {
if (a == b)
{
a++;
}
if (a == c)
{
a++;
}
if (a == d)
{
a++;
}
if (a == e)
{
a++;
}
if (a == f)
{
a++;
}
if (a == g)
{
a++;
}
if (a == h)
{
a++;
}
if (a == i)
{
a++; visuala();
}
}
void datacheckb() {
if (b == c)
{
b++;
}
if (b == d)
{
b++;
}
if (b == e)
{
b++;
}
if (b == f)
{
b++;
}
if (b == g)
{
b++;
}
if (b == h)
{
b++;
}
if (b == i)
{
b++; visualb();
}
}
void datacheckc() {
if (c == d)
{
c++;
}
if (c == e)
{
c++;
}
if (c == f)
{
c++;
}
if (c == g)
{
c++;
}
if (c == h)
{
c++;
}
if (c == i)
{
c++; visualc();
}
}
void datacheckd() {
if (d == e)
{
d++;
}
if (d == f)
{
d++;
}
if (d == g)
{
d++;
}
if (d == h)
{
d++;
}
if (d == i)
{
d++; visuald();
}
}
void datachecke() {
if (e == f)
{
e++;
}
if (e == g)
{
e++;
}
if (e == h)
{
e++;
}
if (e == i)
{
e++; visuale();
}
}
void datacheckf()
{
if (f == g)
{
f++;
}
if (f == h)
{
f++;
}
if (f == i)
{
f++; visualf();
}
}
void datacheckg() {
if (g == h)
{
g++;
}
if (g == i)
{
g++; visualg();
}
}
void datacheckh() {
if (h == i)
{
h++; visualh();
}
}
这就是datacheck()最终如何
答案 1 :(得分:0)
您也可以使用或(||)运算符。
void datacheckf()
{
if (f == g || f == h || f == i) {
f++;
}
if (f == i) {
visualf();
}
}