add ../examples/hanoi.c
authoryu.dongliang <18588496441@163.com>
Wed, 11 Jan 2023 11:37:48 +0000 (19:37 +0800)
committeryu.dongliang <18588496441@163.com>
Wed, 11 Jan 2023 11:37:48 +0000 (19:37 +0800)
examples/hanoi.c [new file with mode: 0644]

diff --git a/examples/hanoi.c b/examples/hanoi.c
new file mode 100644 (file)
index 0000000..1ebb025
--- /dev/null
@@ -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;
+}