def hanoi(n, a, b, c): if(n == 1): print(a, '-->', c) return hanoi(n - 1, a, c, b) print(a, '-->', c) hanoi(n - 1, b, a, c) # Output of hanoi(3, 'A', 'B', 'C'): # A --> C # A --> B # C --> B # A --> C # B --> A # B --> C # A --> C
时间: 2024-10-15 08:51:39