noisewuwei 2014-12-09 06:08 采纳率: 0%
浏览 1680

求大神加注释,小弟看不懂

int main()
{
cout<<"-----迷宫-----"< maze m;
return 0;
}
maze::maze()
{
int i,j;
cout cin>>Height>>Width;
a = new int*[Height];
for(i = 0;i != Height;i++)
{
a[i] = new int[Width];
}
rd = new Road*[Height*Width];
Road *temp = new Road[Height*Width];
cout<<"请输入迷宫矩阵:";
cout<<endl;
for(i = 0;i != Height;i++)
{
for(j = 0;j != Width;j++)
{

        cin>>a[i][j];
        rd[(j+1)+i*Width-1] = &temp[(j+1)+i*Width-1];
        rd[(j+1)+i*Width-1]->state = a[i][j];
        rd[(j+1)+i*Width-1]->num = (j+1)+i*Width-1;
        //cout<<rd[(j+1)+i*n-1]->state;
    }
}
for(i = 0;i != Height;i++)
{
    for(j = 0;j != Width;j++)
    {
        if(i == 0)
        {
            if(j == 0)
            {
                rd[(j+1)+i*Width-1]->N = NULL;
                rd[(j+1)+i*Width-1]->S = rd[(j+1)+(i+1)*Width-1];
                rd[(j+1)+i*Width-1]->W = NULL;
                rd[(j+1)+i*Width-1]->E = rd[(j+1+1)+i*Width-1];
            }
            else if(j == Width-1)
            {
                rd[(j+1)+i*Width-1]->N = NULL;
                rd[(j+1)+i*Width-1]->S = rd[(j+1)+(i+1)*Width-1];
                rd[(j+1)+i*Width-1]->W = rd[(j-1+1)+i*Width-1];
                rd[(j+1)+i*Width-1]->E = NULL;
            }
            else
            {
                rd[(j+1)+i*Width-1]->N = NULL;
                rd[(j+1)+i*Width-1]->S = rd[(j+1)+(i+1)*Width-1];
                rd[(j+1)+i*Width-1]->W = rd[(j-1+1)+i*Width-1];
                rd[(j+1)+i*Width-1]->E = rd[(j+1+1)+i*Width-1];
            }
        }
        else if(i == (Height-1))
        {
            if(j == 0)
            {
                rd[(j+1)+i*Width-1]->N = rd[(j+1)+(i-1)*Width-1];
                rd[(j+1)+i*Width-1]->S = NULL;
                rd[(j+1)+i*Width-1]->W = NULL;
                rd[(j+1)+i*Width-1]->E = rd[(j+1+1)+i*Width-1];
            }
            else if(j == Width-1)
            {
                rd[(j+1)+i*Width-1]->N = rd[(j+1)+(i-1)*Width-1];
                rd[(j+1)+i*Width-1]->S = NULL;
                rd[(j+1)+i*Width-1]->W = rd[(j-1+1)+i*Width-1];
                rd[(j+1)+i*Width-1]->E = NULL;
            }
            else
            {
                rd[(j+1)+i*Width-1]->N = rd[(j+1)+(i-1)*Width-1];
                rd[(j+1)+i*Width-1]->S = NULL;
                rd[(j+1)+i*Width-1]->W = rd[(j-1+1)+i*Width-1];
                rd[(j+1)+i*Width-1]->E = rd[(j+1+1)+i*Width-1];
            }
        }
        else
        {
            if(j == 0)
            {
                rd[(j+1)+i*Width-1]->N = rd[(j+1)+(i-1)*Width-1];
                rd[(j+1)+i*Width-1]->S = rd[(j+1)+(i+1)*Width-1];
                rd[(j+1)+i*Width-1]->W = NULL;
                rd[(j+1)+i*Width-1]->E = rd[(j+1+1)+i*Width-1];
            }
            else if(j == Width-1)
            {
                rd[(j+1)+i*Width-1]->N = rd[(j+1)+(i-1)*Width-1];
                rd[(j+1)+i*Width-1]->S = rd[(j+1)+(i+1)*Width-1];
                rd[(j+1)+i*Width-1]->W = rd[(j-1+1)+i*Width-1];
                rd[(j+1)+i*Width-1]->E = NULL;
            }
            else
            {
                rd[(j+1)+i*Width-1]->N = rd[(j+1)+(i-1)*Width-1];
                rd[(j+1)+i*Width-1]->S = rd[(j+1)+(i+1)*Width-1];
                rd[(j+1)+i*Width-1]->W = rd[(j-1+1)+i*Width-1];
                rd[(j+1)+i*Width-1]->E = rd[(j+1+1)+i*Width-1];
            }
        }
    }
}
cout<<"迷宫矩阵:"<<endl;
for(i = 0;i != Height;i++)
{
    for(j = 0;j != Width;j++)
    {
        cout<<a[i][j]<<"\t";
    }
    cout<<endl;
}
cout<<endl;
cout<<"迷宫节点序号矩阵:"<<endl;
for(i = 0;i != Height;i++)
{
    for(j = 0;j != Width;j++)
    {
        cout<<rd[(j+1)+i*Width-1]->num<<"\t";
    }
    cout<<endl;
}
cout<<endl;
cout<<"请输入入口序号:";
cin>>innum;
cout<<"请输入出口序号:";
cin>>outnum;
if(rd[innum]->state == 0)
{
    if(getout(rd[innum]->num)>0)
    {
        cout<<rd[innum]->num<<"<--进入"<<endl;
    }
    else
    {
        cout<<"没有出口!"<<endl;
    }
}
else
{
    cout<<"没有此入口!"<<endl;
}

}
int maze::getout(int num) //shendu
{
rd[num]->flog = 1;
if(num == outnum)
{
cout<<"出口<--";
return 1;
}
else if(rd[num]->N != NULL && rd[num]->N->state == 0 && rd[num]->N->flog != 1 && getout(rd[num]->N->num)>0)
{
cout<N->num<<"<--";
return rd[num]->N->num;
}
else if(rd[num]->S != NULL && rd[num]->S->state == 0 && rd[num]->S->flog != 1 && getout(rd[num]->S->num)>0)
{
cout<S->num<<"<--";
return rd[num]->S->num;
}
else if(rd[num]->W != NULL && rd[num]->W->state == 0 && rd[num]->W->flog != 1 && getout(rd[num]->W->num)>0)
{
cout<W->num<<"<--";
return rd[num]->W->num;
}
else if(rd[num]->E != NULL && rd[num]->E->state == 0 && rd[num]->E->flog != 1 && getout(rd[num]->E->num)>0)
{
cout<E->num<<"<--";
return rd[num]->E->num;
}
else
{
return -1;
}
}

  • 写回答

1条回答 默认 最新

  • dachaochao1 2014-12-09 06:12
    关注

    你这是指望着别人为您做什么?

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog