mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-10 14:20:43 +08:00
build
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user