Several bug fixes and improments.

This commit is contained in:
krahets
2023-09-24 19:35:32 +08:00
parent 0f0892b8f5
commit e3773b7f76
16 changed files with 17 additions and 15 deletions

View File

@ -14,7 +14,7 @@ function recur(n) {
return n + res;
}
/* 递归转化为迭代 */
/* 使用迭代模拟递归 */
function forLoopRecur(n) {
// 使用一个显式的栈来模拟系统调用栈
const stack = [];
@ -59,7 +59,7 @@ res = recur(n);
console.log(`递归函数的求和结果 res = ${res}`);
res = forLoopRecur(n);
console.log(`递归转化为迭代的求和结果 res = ${res}`);
console.log(`使用迭代模拟递归的求和结果 res = ${res}`);
res = tailRecur(n, 0);
console.log(`尾递归函数的求和结果 res = ${res}`);