projects
/
scf.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
2ec1259
)
add ../examples/hanoi.c
author
yu.dongliang
<18588496441@163.com>
Wed, 11 Jan 2023 11:37:48 +0000
(19:37 +0800)
committer
yu.dongliang
<18588496441@163.com>
Wed, 11 Jan 2023 11:37:48 +0000
(19:37 +0800)
examples/hanoi.c
[new file with mode: 0644]
patch
|
blob
diff --git a/examples/hanoi.c
b/examples/hanoi.c
new file mode 100644
(file)
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;
+}