Thread: Recursion

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    24

    Recursion

    Hi there


    Can anyone supply me with a source for exercises in Recursion?

    I need to practice and do not have but a few exercises


    Cheers

    Gozlan

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    45

    Wink

    A simple exercise is to write a function that calls itself until it returns an a predetermined value of some sort.

    I learned by using an integer and having the function call itself until it returned 3, or 5 or whatever.

    Once you learn how to do this type of recursion, I think it becomes much easier.

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > I need to practice and do not have but a few exercises
    That's the perfect amount of times for recursion to be used too, just a few.
    The world is waiting. I must leave you now.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'll beat Salem to the punch. Here is an example of recursion.

    If you want something to use recursion for, how about a maze generator?
    Code:
    void move( here, direction )
    {
        if( unusedNeighboringCell( here ) )
            move( here, randomUnusedNeighboringCellDirection( ) ) )
        else
            return
    }
    Naturally you'd want this to update 'here' on the additional calls, but I'll leave that as an exercise to you.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template Recursion Pickle
    By SevenThunders in forum C++ Programming
    Replies: 20
    Last Post: 02-05-2009, 09:45 PM
  2. convert Recursion to linear can it be done
    By umen242 in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2008, 02:58 AM
  3. Recursion... why?
    By swgh in forum C++ Programming
    Replies: 4
    Last Post: 06-09-2008, 09:37 AM
  4. a simple recursion question
    By tetra in forum C++ Programming
    Replies: 6
    Last Post: 10-27-2002, 10:56 AM
  5. To Recur(sion) or to Iterate?That is the question
    By jasrajva in forum C Programming
    Replies: 4
    Last Post: 11-07-2001, 09:24 AM