Parsers and compilers may be written in a recursive-descent method. Not the best way to do it, as tools like lex/yacc generate faster and more efficient parsers, but conceptually simple and easy to implement, so they remain common.
Recursion is appropriate whenever a problem can be solved by dividing it into sub-problems, that can use the same algorithm for solving them. Algorithms on trees and sorted lists are a natural fit. Many problems in computational geometry (and 3D games) can be solved recursively using 二分空间划分 (BSP) trees, 脂肪细分, or other ways of dividing the world into sub-parts.
public static void SetReadOnly(Control ctrl, bool readOnly)
{
//set the control read only
SetControlReadOnly(ctrl, readOnly);
if (ctrl.Controls != null && ctrl.Controls.Count > 0)
{
//recursively loop through all child controls
foreach (Control c in ctrl.Controls)
SetReadOnly(c, readOnly);
}
}
Many wire puzzles involve removing a long closed loop of wire by working it in and out of wire rings. These puzzles are recursive.
其中之一被称为“箭头动力学”。我告诉你,你可以找到它,如果你谷歌“箭头动力线困惑”