Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > what is recursion in c++.

Reply
Thread Tools

what is recursion in c++.

 
 
athar.mirchi@gmail.com
Guest
Posts: n/a
 
      01-05-2008
..plz define it.
 
Reply With Quote
 
 
 
 
David Côme
Guest
Posts: n/a
 
      01-05-2008
On Sat, 05 Jan 2008 20:17:17 +0100, http://www.velocityreviews.com/forums/(E-Mail Removed)
<(E-Mail Removed)> wrote:

> .plz define it.



RTFM !
Google is not dead !
 
Reply With Quote
 
 
 
 
Toms hilidhe
Guest
Posts: n/a
 
      01-05-2008
"(E-Mail Removed)" <(E-Mail Removed)> wrote in comp.lang.c++:

> .plz define it.


Mainly "recursion" is where a function calls itself. Something like:

long unsigned Factorial(unsigned const input)
{
if (0 == input) return 1;

if (1 == input) return input;

return input * Factorial(input - 1);
}

--
Toms hilidhe
 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      01-05-2008
On 2008-01-05 19:17:17 +0000, "(E-Mail Removed)"
<(E-Mail Removed)> said:

> .plz define it.


http://en.wikipedia.org/wiki/Recursion

 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      01-05-2008
On Jan 5, 2:17 pm, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> .plz define it.


As the English word suggests: a recursion is simply a function that
calls itself.
Which is neither efficient nor beneficial.
Each call generates a new local stack which eventually all need to be
unwound.
So in C++, its usually replaced with better alternatives.
An example of a preferred alternative would then be a function object
(functor).
Recursive functions have no state (what does that mean?).

To give you an example of recursion:
(that incidentally doesn't do what you'ld expect)

#include <iostream>

void recursion(int n)
{
std::cout << "n = ";
std::cout << n << std::endl;
if(n < 10)
recursion(++n);
}

int main()
{
recursion(0); // prints 11 times
}
 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      01-05-2008
On Jan 5, 2:23 pm, David Côme <(E-Mail Removed)> wrote:
> On Sat, 05 Jan 2008 20:17:17 +0100, (E-Mail Removed)
>
> <(E-Mail Removed)> wrote:
> > .plz define it.

>
> RTFM !
> Google is not dead !


And neither is a little respect.
Some come here hoping others do their homework,
others prefer to ask rather than remain clueless.
Some of those know very little English.

So please: if you feel the need to reply with a patronising remark,
consider ignoring them, redirecting them to Wikipedia/Google or offer
them a link to the FAQ.


 
Reply With Quote
 
douggunnoe@gmail.com
Guest
Posts: n/a
 
      01-05-2008
On Jan 5, 2:19*pm, Salt_Peter <(E-Mail Removed)> wrote:
> On Jan 5, 2:17 pm, "(E-Mail Removed)" <(E-Mail Removed)>


> Each call generates a new local stack which eventually all need to be
> unwound.
> So in C++, its usually replaced with better alternatives.



I agree. But my old college professors thought it was great.

And personally, I also find it more difficult to debug.
 
Reply With Quote
 
David Côme
Guest
Posts: n/a
 
      01-05-2008
On Sat, 05 Jan 2008 21:41:38 +0100, Salt_Peter <(E-Mail Removed)> wrote:

> On Jan 5, 2:23 pm, David Côme <(E-Mail Removed)> wrote:
>> On Sat, 05 Jan 2008 20:17:17 +0100, (E-Mail Removed)
>>
>> <(E-Mail Removed)> wrote:
>> > .plz define it.

>>
>> RTFM !
>> Google is not dead !

>
> And neither is a little respect.
> Some come here hoping others do their homework,
> others prefer to ask rather than remain clueless.
> Some of those know very little English.
>
> So please: if you feel the need to reply with a patronising remark,
> consider ignoring them, redirecting them to Wikipedia/Google or offer
> them a link to the FAQ.
>
>



You could have a basic question because everybody has been noob when he
started programmation.
Howerver before ask usenet,forums... you must make some research.

And recursion on google was the fisrt link so....

 
Reply With Quote
 
Toms hilidhe
Guest
Posts: n/a
 
      01-05-2008
Salt_Peter <(E-Mail Removed)> wrote in comp.lang.c++:

> As the English word suggests: a recursion is simply a function that
> calls itself.
> Which is neither efficient nor beneficial.



It's great though for template metaprogramming. For instance:

template<long unsigned x>
struct Factorial {
static long unsigned const val = x * Factorial<x-1>::val;
};

template<>
struct Factorial<1> {
static long unsigned const val = val;
};

template<>
struct Factorial<0> {
static long unsigned const val = 1;
}


--
Toms hilidhe
 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      01-05-2008
Toms hilidhe wrote:
> Salt_Peter <(E-Mail Removed)> wrote in comp.lang.c++:
>
>> As the English word suggests: a recursion is simply a function that
>> calls itself.
>> Which is neither efficient nor beneficial.

>
>
> It's great though for template metaprogramming. For instance:
>
> template<long unsigned x>
> struct Factorial {
> static long unsigned const val = x * Factorial<x-1>::val;
> };
>
> template<>
> struct Factorial<1> {
> static long unsigned const val = val;
> };
>
> template<>
> struct Factorial<0> {
> static long unsigned const val = 1;
> }


recursion [ri-kur'zhen] - (n) see recursion

--
Jim Langston
(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
va_arg... recursion: changing arguments and the using recursion jononanon@googlemail.com C Programming 8 04-26-2012 08:37 PM
DNS recursion question while studying for 70-293 Kevin Porter MCSE 1 03-18-2006 05:56 AM
DNS recursion question while studying for 70-293 Kevin Porter Microsoft Certification 0 03-16-2006 11:10 PM
recursion with perl B McInnes Perl 4 11-04-2003 06:08 AM
Output buffering problems during recursion Tim Mohler Perl 1 09-16-2003 12:35 AM



Advertisments