This commit is contained in:
krahets
2023-10-26 03:00:28 +08:00
parent f442443773
commit d71e2dd46b
6 changed files with 304 additions and 202 deletions

View File

@@ -1707,12 +1707,12 @@ status: new
/* 使用迭代模拟递归 */
int forLoopRecur(int n) {
int stack[1000]; // 借助一个大数组来模拟栈
int top = 0;
int top = -1; // 栈顶索引
int res = 0;
// 递:递归调用
for (int i = n; i > 0; i--) {
// 通过“入栈操作”模拟“递”
stack[top++] = i;
stack[1 + top++] = i;
}
// 归:返回结果
while (top >= 0) {