标签:interview
class Hanoi { void init(); void resolve() { // Resolve (N) is: // Move (N-1) to stack2 // Move Nth to stack3 // Move (N-1) to stack3 move(n , a, c, b); } void move(int n, Disk a, Disk b, Disk c) // A to B, using C { if (n == 1) b.push(a.pop()); move(n - 1, a, c, b); b.push(a.pop()); move(n - 1, c, b, a); } }
标签:interview
原文地址:http://7371901.blog.51cto.com/7361901/1582223