Recursion

I'm a student in Hochiminh city university of technology, I'm want to have some example about recursion. Thanks alot !!
If you have some example about recursion , please give me by email "huuhoangbk@gmail.com", thanks alot !!
Why not just google "recursion"?

1
2
3
4
size_t factorial( size_t n )
{
    return n ? n * factorial( n - 1 ) : 1;
}

Here is an article about recursion: http://www.cplusplus.com/forum/articles/2231/
Here's an example"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

void recurse(int);

int main() {
int recurseno=-1;
recurse(recurseno);
cin.get();
return 0;
}

void recurse(int recurseno) {
recurseno+=1;
cout << recurseno << " ";
recurse(recurseno);
}


This will eventually crash because it recurses so many times. It tells you how many recursions it has been through, so that's cool. You can find out how far you get. I got 130155 before Windows reported an error.
In order to understand recursion, one must first understand recursion!

1
2
3
4
long fib(long x)
{
    return (x<3)?1:(fib(x-1)+fib(x-2));
}
Last edited on
Last edited on
That's very philosophical of you, demosthenes :)
there is a famous problem on recursion..

8 queens problem
.. where you have to do recursion and backtracking also..
find an article i posted here:

http://www.codeproject.com/KB/cpp/8Queen_Problem.aspx


if you didnt understand i will help.. :)

Topic archived. No new replies allowed.