谁能用非递归算法解决老鼠走迷宫问题?我要源程序.!!!

来源:百度知道 编辑:UC知道 时间:2024/06/06 07:33:30
要求:必需是要用C语言编写的.
不要太长就好.

#include<iostream>
#include<string>
#include<ctime>
#include<cstring>
using namespace std;

struct coordinate
{
int x,y;
int dir;
};

class stack
{
public:
coordinate *c;
int MaxSize;
int top;
stack(int);
void Push(const coordinate&);
coordinate Pop();
bool empty();
void Output();
};

stack::stack(int ms)
{
if(ms<=0){cerr<<"invalid ms"<<endl;exit(1);}
MaxSize=ms;
c=new coordinate[MaxSize];
if(!c)
{
cerr<<"memory allocation failure"<<endl;
exit(1);
}
top=-1;
}

void stack::Push(const coordinate& coor)
{
if(top==MaxSize)
{
cerr<<"stackoverflow"<<endl