各位能帮小弟我看一下吗?程序莫名奇妙
各位能帮我看一下吗?程序莫名奇妙
bool trace(long r,long c,jks::CBitMatrix& m,std::stack <POINT> & trial)
{
long x = trial.top().x;
long y = trial.top().y;
long i,j,tx,ty,sum=0;//sum 除了自身和上点,临近点的数量
for (i=r-1;i <r+2;i++)
{
for (j=c-1;j <c+2;j++)
{
if (i==r && j==c) {trial.push(point(r,c));}
else if(i==x && j==y) continue;//没问题
else if(m[i][j])
{
if(!sum++) {tx=i;ty=j;}
else return true;//branch
}
}
}
但是我这样写
bool trace(long r,long c,jks::CBitMatrix& m,std::stack <POINT> & trial)
{
long i,j,tx,ty,sum=0;//sum 除了自身和上点,临近点的数量
for (i=r-1;i <r+2;i++)
{
for (j=c-1;j <c+2;j++)
{
if (i==r && j==c) {trial.push(point(r,c));}
else if(i==trial.top().x && j==trial.top().y) continue;
else if(m[i][j])
{
if(!sum++) {tx=i;ty=j;}
else return true;//branch
}
}
}
if(i==trial.top().x && j==trial.top().y) 就是进不去!!!
是不是我的写法有问题,我这个奇怪了。
希望各位能指点一下why?
------解决方案--------------------
top和push
就是啦,多用临时变量意思表达清楚好一点
bool trace(long r,long c,jks::CBitMatrix& m,std::stack <POINT> & trial)
{
long x = trial.top().x;
long y = trial.top().y;
long i,j,tx,ty,sum=0;//sum 除了自身和上点,临近点的数量
for (i=r-1;i <r+2;i++)
{
for (j=c-1;j <c+2;j++)
{
if (i==r && j==c) {trial.push(point(r,c));}
else if(i==x && j==y) continue;//没问题
else if(m[i][j])
{
if(!sum++) {tx=i;ty=j;}
else return true;//branch
}
}
}
但是我这样写
bool trace(long r,long c,jks::CBitMatrix& m,std::stack <POINT> & trial)
{
long i,j,tx,ty,sum=0;//sum 除了自身和上点,临近点的数量
for (i=r-1;i <r+2;i++)
{
for (j=c-1;j <c+2;j++)
{
if (i==r && j==c) {trial.push(point(r,c));}
else if(i==trial.top().x && j==trial.top().y) continue;
else if(m[i][j])
{
if(!sum++) {tx=i;ty=j;}
else return true;//branch
}
}
}
if(i==trial.top().x && j==trial.top().y) 就是进不去!!!
是不是我的写法有问题,我这个奇怪了。
希望各位能指点一下why?
------解决方案--------------------
top和push
就是啦,多用临时变量意思表达清楚好一点