C++中STL和栈的问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 17:52:51
下面这个程序为什么编译能通过,但运行就报错?注:我用了STL里的栈类,是不是STL用得不对呀?

#include<iostream>
#include<stack>
using namespace std;

struct step
{
int row,col;
int dir;
};
bool maze_probe(int **maze,int m,int n,stack<step> &path)
{
int **mazemap=new int*[m+2];
for(int i=0;i<m+2;i++)
mazemap[i]=new int[n+2];
bool **have_been=new bool*[m+2];
for(int i=0;i<m+2;i++)
have_been[i]=new bool[n+2];
for(int i=0;i<m+2;i++)
for(int j=0;j<n+2;j++)
{
have_been[i][j]=false;
if(i==0||i==m+1||j==0||j==n+1)mazemap[i][j]=1;
else mazemap[i][j]=maze[i-1][j-1];
}
int move[8][2]={(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)};
int pre_row=1,pre_col=1;
if(mazemap[pre_row][pre_col]==1)return false;
step pre={pre_row,pre_col,0};
path.push(pre);
have_been[pre_row][pre_col]=true;

while(1)
{
pr

给你改对了, 自己比较下哪里错了吧。

#include<iostream>
#include<stack>
using namespace std;

struct step
{
int row,col;
int dir;
};
bool maze_probe(int **maze,int m,int n,stack<step> &path)
{
int **mazemap=new int*[m+2];
for(int i=0;i<m+2;i++) mazemap[i]=new int[n+2];
bool **have_been=new bool*[m+2];
for(i=0;i<m+2;i++) have_been[i]=new bool[n+2];
for(i=0;i<m+2;i++)
for(int j=0;j<n+2;j++)
{
have_been[i][j]=false;
if(i==0||i==m+1||j==0||j==n+1)mazemap[i][j]=1;
else mazemap[i][j]=maze[i-1][j-1];
}
int move[8][2]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}};
int pre_row=1,pre_col=1;
if(mazemap[pre_row][pre_col]==1)return false;
step pre={pre_row,pre_col,0};
path.push(pre);
have_been[pre_row][pre_col]=true;

while(1)
{
pre.row=pre_row;
pre.col=pre_col;
if(p