Tag: 广度优先搜索

如何在迷宫中打印从源到目标的BFS路径

我正在尝试实现BFS,以便找到迷宫中从源到目标的最短路径。 我遇到的问题是我无法打印路径,它在迷宫中打印了’*’,但是如何在不打印所有被访问节点的情况下从BFS的前辈中提取路径? 这是我编译的代码: #include #include #include struct coord{ //This is a struct I’ll use to store coordinates int row; int col; }; //———QUEUE.C——-// struct TQueue{ struct coord *A; int QUEUE_MAX; }; typedef struct TQueue *Queue; Queue initQueue(int size){ // Initialize the queue Queue Q = malloc(sizeof(struct TQueue)); Q->A = malloc(size*sizeof(struct coord)); Q->QUEUE_MAX = size+1; Q->A[0].row […]