From 67273cb1cf12207e55a2cff8d1bf0351ef8f7477 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Wed, 11 Jan 2023 19:37:48 +0800 Subject: [PATCH] add ../examples/hanoi.c --- examples/hanoi.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 examples/hanoi.c diff --git a/examples/hanoi.c b/examples/hanoi.c new file mode 100644 index 0000000..1ebb025 --- /dev/null +++ b/examples/hanoi.c @@ -0,0 +1,20 @@ +int printf(const char* fmt, ...); + +int count = 0; + +void hanoi(int n, char a, char b, char c) +{ + if (1 == n) + printf("count: %d, n: %d, %c->%c\n", count++, n, a, c); + else { + hanoi(n-1, a, c, b); + printf("count: %d, n: %d, %c->%c\n", count++, n, a, c); + hanoi(n-1, b, a, c); + } +} + +int main() +{ + hanoi(4, 'A', 'B', 'C'); + return 0; +} -- 2.25.1