Algorithms_Hanoi

#include "stdio.h"

void Hanoi(char a,char b,char c,int n);
void main()
{
	Hanoi('A','B','C',3);
}

void Hanoi(char a,char b,char c,int n)
{
	if(n==1)
		printf("%c -> %c\n",a,c);
	else
	{
		Hanoi(a,c,b,n-1);
		printf("%c -> %c\n",a,c);
		Hanoi(b,a,c,n-1);
	}
}
posted @ 2011-09-24 19:20  legendmaner  阅读(131)  评论(0编辑  收藏  举报