参考了一下easyx.cn的代码 并加以修改 逻辑更加清楚 #include<easyx.h> #define MAX 5 typedef struct MyRect { int left; int top; int right; int bottom; }MYRECT; typedef struct MyStack { MYRECT rect[MAX+1]; int top; }MYSTACK; MYSTACK g_Pillar[3] = { 0 }; int g_nPan = MAX; // 函数声明 void Hannoi(int n, char a, char b, char c); // 汉诺塔递归 void Move (int n, char a, char b); // 移动过程 int switchab(char a); int main() { initgraph(800, 650); setbkcolor(WHITE); cleardevice(); //三根柱子 setlinecolor(RED); line(400, 110, 400, 500); line(600, 110, 600, 500); line(200, 110, 200, 500); //底座 setfillcolor(LIGHTGRAY); fillrectangle(80, 501, 720, 510); //------------- for (int i = 0; i < MAX; i++) { g_Pillar[0].top++; g_Pillar[0].rect[g_Pillar->top].left = 115 + i * 5; g_Pillar[0].rect[g_Pillar->top].top