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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器