⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sheji.c

📁 此文件包含迷宫的经典算法和易错的地方。能实现查找路径功能。
💻 C
字号:
#include<stdio.h>
#define MAX_STACK  100
typedef struct
{  int row;
   int col;
   int dir;
}element;
element stack[MAX_STACK];

typedef struct
{
	int EXIT_ROW;
	int EXIT_COL;
	int mark;
}exit;

typedef struct
{
	int next_row;
	int next_col;
}maze;

void InitialStack()
{
	//stack[]=0;
}
void InitialMaze(int Maze[],int num)
{
//int mark=0;


}

void Path(int maze[])
{
	int i,row,col,next_row,next_col,dir,found=0;
	int vert,horiz;

	element position,move[dir];
	int mark[1][1]=1;
	int top=0;
	stack[0].row=1;
	stack[0].col=1;
	stack[0].dir=1;
	while(top>-1&&!found)
	{
		//position=delete(&top);
		row=position.row;
		col=position.col;
		dir=position.dir;
		while(dir<8&&!found)
		{
			next_row=row+move[dir].vert;
			next_col=col+move[dir].horiz;
			if(next_row==EXIT_ROW&&next_col==EXIT_COL)
				found=1;
			else
				if(!maze[next_row][next_col]&&!mark[next_row][next_col])
				{
					mark[next_row][next_col]=1;
					position.row=row;
					position.col=col;
					position.dir=++dir;
				//	add(&top,position);
					row=next_row;
					col=next_col;
					dir=0;
				}
				else
					++dir;
		}
	}

	if(found)
	{
		printf("路径是:\n");
		printf("行  列\n");
		for(i=0;i<=top;i++)
			printf("%2d%5d\n",stack[i].row,stack[i].col);
		printf("%2d%5d\n",EXIT_ROW,EXIT_COL);
	}
	else
		printf("迷宫没有出路\n");
}

void main()
{
	int maze[8][8];
	InitialStack();
	InitialMaze(maze,8);
	Path(maze);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -