Look at my previous answer to a recursion question. Understanding recursion in terms of function implementation I don’t know if it will be helpful to you.
If you want to learn recursion, you must first learn recursion.
Recursion is the stuffing of steamed buns, and the limit is steamed buns.
Gives a normal code example:
Suppose we want to traverse a [nested] data structure, such as [the children attribute of a DOM element or a DOM element of the same type], then the simplest and most common recursion will be used: the function calls itself, layer by layer Unnesting only requires one or two lines of JS:
Recursion is actually not difficult to understand. Let me give you an example. There are apples on only one floor of a 6-story building. If we find apples on any floor, we will stop. . There will be two results when searching once. You don’t need to search down to make a judgment. Searching down means repeating the first process. This is recursion.
int i;
int function a(i){
if (i < 2) return a(i+1);
else return i;
}
a(0); //执行后返回2
The above code is easy to understand without writing standards. Recursion means calling itself to form a nest. Because there is only one return statement, so after calling a(0) we can see it like this: Nested in:
Look at my previous answer to a recursion question. Understanding recursion in terms of function implementation
I don’t know if it will be helpful to you.
The simple understanding is: the function calls
itself
.Qualified recursion must have an
ending condition
.Understand these 2 points and you’ll be fine.
If you want to learn recursion, you must first learn recursion.
Recursion is the stuffing of steamed buns, and the limit is steamed buns.
Gives a normal code example:
Suppose we want to traverse a [nested] data structure, such as [the children attribute of a DOM element or a DOM element of the same type], then the simplest and most common recursion will be used: the function calls itself, layer by layer Unnesting only requires one or two lines of JS:
Recursion is actually not difficult to understand. Let me give you an example. There are apples on only one floor of a 6-story building. If we find apples on any floor, we will stop. . There will be two results when searching once. You don’t need to search down to make a judgment. Searching down means repeating the first process. This is recursion.
The above code is easy to understand without writing standards. Recursion means calling itself to form a nest.
Because there is only one return statement, so after calling a(0) we can see it like this:
Nested in:
Coming back:
Experience of an experienced driver: practice more and learn more