homework5 傅继晗 Version 0 |
|
👤 Author: by 549308442qqcom 2016-11-15 19:55:26 |
40.create a recursive function like hanoi()
procedure hanoi(n,x,y,z):
if n=1,print(x"->"z);
else hanoi(n-1,x,z,y);
print(x"->"z);
hanoi(n-1,y,x,z);
hanoi(n,"x","y","z");
41 initial an Array containing n elements,and the peg numbered A B C in clock wise.rings stack at A at beginning.
A->Array[];
for(i=1,i<=n,i++):
if(i%2==0)Array[i]:
case:A {print(A->C)}C->Array[i]}
case:B{print(B->A)}A->Array[i]}
case:C {print(C->B)}