数据结构C++语言解决迷宫问题

标题: 迷宫问题
时 限: 100000 ms
内存限制: 100000 K
总时限: 3000 ms
描述: 迷宫问题

迷宫是一个二维矩阵,其中1为墙,0为路,3为入口,4为出口.要求从入口开始,从出口结束,按照 下,左,上,右 的顺序来搜索路径.
输入: 迷宫宽度w 迷宫高度h
迷宫第一行
迷宫第二行
...
迷宫第h 行
输出: 入口横坐标1 入口纵坐标1
横坐标2 纵坐标2
横坐标3 纵坐标3
横坐标4 纵坐标4
...
横坐标n-1 纵坐标n-1
出口横坐标n 出口纵坐标n
输入样例: 8 10
1 1 1 1 1 1 1 1
1 0 1 1 0 1 0 1
1 0 1 0 0 1 0 1
1 1 0 3 1 0 1 1
1 0 0 1 0 0 4 1
1 0 0 0 0 1 1 1
1 0 1 0 0 1 0 1
1 0 1 0 0 0 1 1
1 1 1 1 0 0 0 1
1 1 1 1 1 1 1 1
输出样例: 3 3
2 3
2 4
2 5
3 5
3 6
3 7
4 7
4 6
4 5
4 4
5 4
6 4

这个编程未完成,等待中

代码如下:

 #include<iostream>
using namespace std;

int main()
{
    //矩阵初始化
    int **migong;
    int h, w;
    int m, n;
    cout << "请输入迷宫高度h和迷宫宽度w:" << endl;
    cin >> h >> w;
    migong = new int *[h];
    for (int i = 0; i < h ; i++)
    {
        migong[i] = new int[w];
    }
    for (m = 0; m < h ; m++)
    {
        for (n = 0; n < w ; n++)
        {
            cin>>migong[m][n] ;
        }
    }
    //输出矩阵
    for (m = 0; m < h; m++)
    {
        for (n = 0; n < w; n++)
        {
            cout << migong[m][n] << "    ";
        }
        cout << endl;
    }
    int temp = 0;
    if (h >= w)
        temp = h;
    else
        temp = w;
    int *path_row = new int;//通行路径的行
    int *path_column = new int;//通行路径的列
    for (int i = 0; i < temp; i++)
        path_row[i] = path_column[i] = 0;
    int row = 0;
    int column = 0;
    int count = 0;
    do
    {
        column = 0;
        do
        {
            switch (migong[row][column])
            {
            case 3:
                cout << "入口坐标为:" << "(" << row << "," << column << ")" << endl;
            }
            switch (migong[row][column])
            {
            case 0:
                path_row[count] = row;
                path_column[count] = column;
                cout << "(" << row << "," << column << ")" << endl;
                count++;
                break;
            case 1:
                break;
            }
            switch (migong[row][column])
            {
            case 4:
                cout << "出口坐标为:" << "(" << row << "," << column << ")" << endl;
            }
            column += 1;
        } while (column < w);
        row += 1;
    }while (row < h);
    for (m = 0; m < h ; m++)
    {
        delete[] migong[m];
    }
    delete migong;
    delete path_row;
    delete path_column;
    system("pause");
    return 0;
}

不过运行提示出错,我也弄不懂哪儿出了错,待我问问去……