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

📄 4-9.c

📁 数据结构经典算法一书源代码和习题解答实现代码。
💻 C
字号:
#include "stdio.h"
#define MAX_STACK   100  /* maximum stacksize */
typedef  struct {
	int row;
	int col;
	int  dir;
}element;
element  stack[MAX_STACK];
void InitialStack()
{
	//初始化栈
}
void InitialMaze(int Maze(),int num)
{
	//初始化迷宫
}
void Path(int maze[])
{     /* 如果存在出路,则把出来打印出来*/
    int   i, row, col, next_row, next_col, dir, found = 0;
    element    position;
    mark[1][1]=1;    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", stack[i].row, stack[i].col);
        printf ("%2d%5d\n",row,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 + -