recursive function

May 15, 2014 at 7:44pm
Can someone show how to do recursive function by hand not complier.

thank
May 15, 2014 at 7:46pm
May 15, 2014 at 7:51pm
Length of list is:
    0 if the list is empty
    1 (for the first element in the list) + Length of remainder of list

So length of () is 0

Length if (hello) =
1 + length of () =
1 + 0 =
1

Length of (hello friend, come with us) =
1 + length of (friend, come with us) =
1 + 1 + length of (come with us) =
1 + 1 + 1 + length of (with us) =
1 + 1 + 1 + 1 + (us) =
1 + 1 + 1 + 1 + 1 + length of () =
1 + 1 + 1 + 1 + 1 + 0 =
5

Hope this helps.
May 15, 2014 at 10:08pm
I still don't understand
May 15, 2014 at 10:10pm
about this

1
2
3
4
5
6
7
8
void Example (int Z)
{
         if (z!=0)
         {
             Example (z/2);
             cout << K%2;
         }
}
May 16, 2014 at 12:24am
Cleaned up the example:

1
2
3
4
5
6
7
8
void DisplayInBinary( unsigned Z )
{
    if (Z != 0)
    {
        Example( Z / 2 );
        cout << (Z % 2);
    }
}


Oh, wait... same person?

Ever read, "wash, rinse, repeat" on your shampoo bottle? How many times are you supposed to repeat? (Until your hair is clean.)

Grab a handful of chocolates. How many do you have?
Eat one. That's one chocolate (hah hah hah hah).

How many chocolates did you have? One plus the number of chocolates in your hand.

Just keep going until you have an empty hand.


You need to think about this a bit to wrap your brain around it. Don't give up.
May 16, 2014 at 1:01am
I got it now
May 16, 2014 at 1:02am
lol. One question about String,

when it say s2.replace (3,2 s1);

i know that 3 is move 3 place and what 2?
Last edited on May 16, 2014 at 1:02am
Topic archived. No new replies allowed.