程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c++-C++ 迷宮問題,代碼運行除了正確結果卻提示出錯

c++-C++ 迷宮問題,代碼運行除了正確結果卻提示出錯

編輯:編程綜合問答
C++ 迷宮問題,代碼運行除了正確結果卻提示出錯

代碼如下:

 #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;
}

麻煩各位大神看看是哪兒出錯了

最佳回答:


如果結果正確卻丟出異常,顯然是delete的問題。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved