From: yu.dongliang <18588496441@163.com> Date: Wed, 11 Jan 2023 11:37:48 +0000 (+0800) Subject: add ../examples/hanoi.c X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=67273cb1cf12207e55a2cff8d1bf0351ef8f7477;p=scf.git add ../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; +}