"What is recursion"
Recursion is called repeatedly by the function itself.
There are two points to note when using recursion:
1) recursion is the invocation of itself within a procedure or function;
2) When using recursion, there must be a definite recursive end condition called a recursive exit.
Recursion is divided into two stages:
1) Recursion: The solution of the complex problem is pushed to a simpler problem than the original problem;
2) Regression: When the simplest case is obtained, it is gradually returned and the complex solution is obtained in turn.
"What is Iteration"
Use the original value of the variable to derive a new value for the variable. If recursion calls itself by itself, the iteration is a non-stop call to B.
"The difference between recursion and iteration"
Recursion and function call itself; iteration is a loop, and there is a self-change in the loop body.
"Code parsing"
This is recursive int Funca (int n) { if (n > 1) return N+funca (n-1); else return 1; } This is the iteration int FUNCB (int n) { int i,s=0; for (i=1;i<n;i++) s+=i; return s; }
here recursion, that is, Funa itself calls; The iteration here, that is, the FUNB constant cyclic invocation of s, makes s self-changing;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C + + iterative and recursive analysis