logo资料库

迷宫问题的C++算法实现.doc

第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
资料共4页,全文预览结束
#ifndef MMIGONG_H #define MMIGONG_H #define MAX_SIZE 100 #include using namespace std; struct Node { int x; int y; int di; }; class Stack { private: int rrow; int ccolm; int top; int count; int minlenght; Node stack[MAX_SIZE]; Node sstack[MAX_SIZE]; public: //初始化 Stack(); //int **InsortMiGong(); void FindPath(int ab[][10]); //输入迷宫(即一个二维数组) //找出迷宫的出路 }; Stack::Stack() { //初始化 rrow=0; ccolm=0; top=-1; count=1; minlenght=MAX_SIZE; } //输入迷宫(即一个二维数组) /*int ** Stack::InsortMiGong() { int row=1,colm=1; while(true) { cout<<"请输入迷宫的行数和列数:";
cin>>row>>colm; if(row<=0||colm<=0) { cout<<"输入错误!请重新输入:"<>mg[i][j]; return mg; }*/ void Stack::FindPath(int ab[][10]) { //找出迷宫的出路 int a,b,di,find,k; top++;stack[top].x=1; stack[top].y=1; stack[top].di=-1; ab[1][1]=-1; while(top>-1) { a=stack[top].x; b=stack[top].y; di=stack[top].di; if(a==8&&b==8) { cout<
cout<
cout<<"其长度为:"<"; if(!((k+1)%10)) cout<
分享到:
收藏