3.1核心数据结构的实现
zhouyufan 1 year ago
parent 20127db853
commit 779f291e5b

@ -0,0 +1,78 @@
1.迷宫与栈类型
int maze[M][N],row,col;
typedef struct 栈操作函数
void Init_hand_Maze(int maze[M][N],int m,int n)
{int i,j;
for(i=1;i<=m+1;i++)
for(j=1;j<=n+1;j++)
{maze[i][j]=1;
}
cout<<" 请按行输入迷宫, 0表示通路 1 表示障碍:"<<endl; for(i=1;i<m+1;i++)
for(j=1.j<n+1;j++)
cin>>maze[i][j];
for(i=1;i<m+1;i++){
for(j=1:j<n+1;j++)
{
if(maze[i][j]!=0&&maze[i][j]!=1)(
cout<<” 您输入有误,请重新输入";
Init_hand_Maze(maze,m,n);
}
}
}
}
时间复杂度 Om*n
void Init_automatic_Maze(int maze[M][N],int m,int n) 求解迷宫
Status MazePath(Stack &S,MazeType &e,int maze[M][N], int m, int n)
{
do
{
if(maze[][]==0) 打印路径
int PrintPath(Stack S,int maze[M][N],int row,int col)
{
if==
cout<<"\n===============================================\n";
cout<<" 此迷宫无解 \n\n";
return ERROR;
}
MazeType e; while!=
{Pop(S,e); maze[][]=+10);}
cout<<"\n===============================================\n";
cout<<" 路径为 :"<<endl;
int i,j:
for(i=1;i<row+1;i++)
{
for(j=1;j<col+1:j++)
{
switch(maze[i][j])
{
case 0:
cout<<" 口";
break;
case 1:
cout<<" ■";
break;
case 2:
cout<<"※”;
break;
case 10:
cout<<" →";
break;
case 11:
cout<<" ↓";
break;
case 12:
cout<<" ←";
break;
case 13:
cout<<" ↑";
break;
}
}
cout<<endl;
}
cout<<" 完成!"<<endl;
return OK;
}
Loading…
Cancel
Save