如何编写递归函数的方法定义
How to write the method definition for a recursive function?
Printer_Helper是一个递归函数,用于打印链表的内容。
struct Node
{
string data;
Node *next;
}
void List::print()
{
Print_Helper(head);
}
如何编写递归函数的方法定义?
基本上递归是这样工作的:
- 你有一个问题(打印一个节点)
- 部分问题是为当前问题的一小部分解决相同的问题(打印子节点)
- 在某些情况下,没有更小的问题存在,你可以停止解决(没有更多的子节点)
在这种情况下,它的工作方式是:
print content of current node
if there are any child nodes:
for each child node:
call this function with the child node
相关文章:
- 在方法定义中显式指定命名空间
- 没有针对完全专用模板类的外联虚拟方法定义
- 将虚拟方法定义为私有方法时会发生什么情况?
- 单独的类声明和方法定义文件问题
- Eclipse CDT 不了解方法定义是什么
- C 方法定义具有模板
- Eclipse CDT将方法定义定义到标头文件
- 模板方法定义的问题 - 错误C2244:无法将函数定义与现有声明匹配
- 如何为 Product* getProductFromID(std::string)编写方法定义;.
- gdb 中的方法定义没有源代码
- 方法定义中的错误"passing const List<int> as this argument discards qualifiers"
- Sendmessage在方法定义内部无法正常工作
- C 公共方法定义后定义
- C++模板方法定义在类中不匹配
- 为什么通用模板方法定义与模板类专用化不匹配?
- 方法定义中的C++模板参数
- C++方法定义和变量声明
- 在继承层次结构中将方法定义为虚拟方法一次,以使多态性发挥作用
- 未为非访问器方法定义C++类属性
- 无法将一个类的方法定义为另一个类的好友