#define MAX_NUMS 15
struct column{
int * disc;
int nums;
char name;
};
typedef struct column * column_t;
void hanoi(int n, column_t from, column_t to, column_t via) //递归要解决的问题
{
if (n == 1) //最简单的情况的处理
{
to->disc[to->nums] = from->disc[from->nums - 1];
to->nums++;
from->nums--;
printf("%c -> %c\n", from->name, to->name);
return;
}
hanoi(n - 1, from, via, to); //递归调用,递推到当前层
hanoi(1, from, to, via);
hanoi(n - 1, via, to, from);
}
void hanota(int* A, int ASize, int* B, int BSize, int** C, int* CSize){
column_t a = malloc(sizeof(struct column));
column_t b = malloc(sizeof(struct column));
column_t c = malloc(sizeof(struct column));
a->disc = A;
a->nums = ASize;
a->name = 'a';
b->disc = malloc(MAX_NUMS * sizeof(int));;
b->nums = 0;
b->name = 'b';
c->disc = malloc(MAX_NUMS * sizeof(int));;
c->nums = 0;
c->name = 'c';
hanoi(a->nums, a, c, b);
*C = c->disc;
*CSize = c->nums;
}