Matlab的递归调用,好久不用matlab了,练练手。
global handCount; handCount = 1; huuotsun(1, 2, 3, 3)
|
function huuotsun(cur, buf, tar, num) global handCount; if num == 1 str = sprintf(‘c %d plate %d to %d ‘, handCount, cur, tar); disp(str); handCount = handCount + 1; else huuotsun(cur, tar,buf, num -1); str = sprintf(‘c %d plate %d to %d ‘, handCount, cur, tar); disp(str); handCount = handCount + 1; huuotsun(buf, cur,tar, num -1); end end
|
时间: 2024-10-14 11:01:44