Add recurse.md
ci/woodpecker/push/test Pipeline was successful Details

This commit is contained in:
Sainnhe Park 2023-01-31 15:39:26 +08:00
parent 5b947bfadc
commit 37ff349aa0
2 changed files with 23 additions and 0 deletions

View File

@ -41,6 +41,10 @@
- [总结](./stl.md)
# 技巧
- [递归](./recurse.md)
# 经典代码
- [合并两个有序链表](./merge_two_sorted_linked_lists.md)

19
notes/src/recurse.md Normal file
View File

@ -0,0 +1,19 @@
# 递归
```cpp
/* 足以描述下一次迭代完成状态的参数 */ recurseFunc(/* 足以完成当前迭代的参数 */) {
if (/* 结束条件 */) {
/* statements */
}
/* 进行下一次迭代 */
/* 进行当前迭代 */
/* 返回当前迭代结果 */
}
```
并不是一定要先进行下一次迭代再进行当前迭代,实际上如果不需要下一次迭代就能完成当前迭代,那么其实也可以先进行当前迭代。
先进行当前迭代和先进行下一次迭代在迭代顺序上也有差别,参考二叉树的前中后序遍历。