Tower of Hanoi

来源:互联网 发布:支付宝能解绑淘宝号码 编辑:程序博客网 时间:2024/05/17 06:44
#include <stdio.h>#include <stdlib.h>void towerOfHanoi(int n, char from, char to, char temp);int main(){    towerOfHanoi(5,'A','C','B');    return 0;}void towerOfHanoi(int n, char from, char to, char temp){    if(n > 0){       towerOfHanoi(n-1, from, temp, to);        printf("move from disk %d from %c to %c\n", n,from, to);        towerOfHanoi(n-1, temp, to, from);    }}