someone explain recursion ... in simple terms =S
-
- http://www.doctor-dark.co.uk
- 2009-11-06 @ 12:08:19
-
- 2009-11-07 @ 14:35:37
studying computing , the tutor explained it , and i understand the concept, but i just don`t understand how to go about writing my own lOL . no worries
xoxo-
- http://www.doctor-dark.co.uk
- 2009-11-08 @ 17:48:04
It's one of those things that either comes to you in a blinding flash, in which case you start using it far too often (and I have a good example of that, since there is an iterative solution to the Towers of Hanoi problem that is better than the usually quoted recursive solution) or you end up programming in languages that don't have recursion, or you give up and do something less interesting than programming.
Basically, you just need a routine that gets you closer to the answer, and a test to see when you have got there.
Googling for examples of recursive programs should (eventually) find you some sensible examples, like the Wikipedia one of factorials...
unsigned int factorial(unsigned int n)
{
if (n <= 1)
{
return 1;
}
else
{
return n * factorial(n-1);
}
}
// Sorry but the indenting has been eaten by blog.co.uk
I hope that helps, but I can't tell if it will, because my brain has been poisoned by the act of getting a First in Maths and Computing, so I think that's easy and obvious, while sensible humans might not. Even saying "do a trace" might not help. One tries to help, just because computing really IS interesting.
Cheers, Walrus-
- 2009-11-08 @ 23:17:00
aah , that did help a little ,
it seems simpler now
=) .
thankyou for your help =)
xoxo
sarah
-
- http://www.doctor-dark.co.uk
- 2009-11-09 @ 07:13:42
All in a days work for Notverysupernerd!
-
- 2009-11-09 @ 11:35:01
hahah ... Keep Smiling =)

The_Walrus
Pro
Sorry, I'm a bit busy. Are you studying IT? Ask tutor...