- initial import
git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/* tower of hanoi */
|
||||
|
||||
int num[4];
|
||||
|
||||
mov( int n, int from, int to)
|
||||
{
|
||||
int other;
|
||||
if( n == 1) {
|
||||
num[from] = num[from] - 1;
|
||||
num[to] = num[to] + 1;
|
||||
printf("%d -> %d\n",from,to);
|
||||
} else {
|
||||
other = 6 - from - to;
|
||||
mov(n-1, from, other);
|
||||
mov(1, from, to );
|
||||
mov(n-1, other, to);
|
||||
}
|
||||
}
|
||||
|
||||
main() {
|
||||
int disk;
|
||||
printf("%f\n", 1.375f);
|
||||
|
||||
disk = 3;
|
||||
num[0] = 0;
|
||||
num[1] = disk;
|
||||
num[2] = 0;
|
||||
num[3] = 0;
|
||||
mov(disk,1,3);
|
||||
}
|
||||
Reference in New Issue
Block a user