以下是使用 C 语言解决迷宫问题的代码示例:
``` #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h>
#define STACK_SIZE 100
typedef struct { int row; int col; } Position;
typedef struct { Position data[STACK_SIZE]; int top; } Stack;
void initStack(Stack* stack) { stack->top = -1; }
bool isStackEmpty(Stack* stack) { return stack->top == -1; }
bool isStackFull(Stack* stack) { return stack->top == STACK_SIZE - 1; }
void push(Stack* stack, Position element) { if (isStackFull(stack)) { printf("栈已满\n"); return; } stack->data[++stack->top] = element; }
Position pop(Stack* stack) { if (isStackEmpty(stack)) { printf("栈已空\n"); return (Position){-1, -1}; } return stack->data[stack->top--];