1. 背景说明
假设有 3 个分别命名为 X、Y 和 Z 的塔座,在塔座 X 上插有 n 个直径大小各不相同、依小到大编号为 1, 2,…,n 的圆盘。
现要求将 X 轴上的 n 个圆盘移至塔座 Z 上并仍按同样顺序叠排,圆盘移动时必须遵循下列规则:
(1) 每次只能移动一个圆盘;
(2) 圆盘可以插在 X、Y 和 Z 中的任一塔座上;
(3) 任何时刻都不能将一个较大的圆盘压在较小的圆盘之上。
2. 示例代码
1)errorRecord.h
// 记录错误宏定义头文件
#ifndef ERROR_RECORD_H
#define ERROR_RECORD_H
#include <stdio.h>
#include <string.h>
#include <stdint.h>
// Extracts the file name from the file path
#define FILE_NAME(X) strrchr(X, '\\') ? strrchr(X, '\\') + 1 : X
// Define DEBUG macro for enabling debug mode
#define DEBUG
// Print error message
#ifdef DEBUG
#define ERR_RECORD(ERR_CODE, ...) do { \
printf(ANSI_COLOR_BRIGHT