Thread: recoursive function please help

  1. #1
    Unregistered
    Guest

    Angry recoursive function please help

    1 5 7 1 2 3
    2 4 3 4 5 UNIVERSITY-EXERCISE
    8 6 6 7 8
    A B

    I need to write a recoursive function, that calculates
    the way to reach the B-configuration of the numbers
    when called with the A-configuration. (or any other A-
    configuration)

    QUESTION: POSSIBLE? PLEASE HELP ME WITH AN
    ALGORITHM OR FUNCTION BODY, I'VE NO IDEA OF HOW
    TO SOLVE THIS EXERCISE.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    20
    Which is A and which B?
    BTW, it's spelled recursive.
    Al

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    60
    1-5-6***1-2-3
    8-2-3***4-x-5
    x-7-4***6-7-8
    --A---------B---
    A card, for example '8', can only be moved to a
    free place, marked with x. ? No idea.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    20

    recursive function help

    This is a sorting problem. Here's the answer, in English.
    1. Create an array,

    2. success is when each slot contains its number, i.e. 1 has 1, 2 has 2, etc, except that 5 contains 0 which is what we use for x, and slot 0 is not used at all.

    3. step 1, read the A position into the array. Suppose it looks like this: 9999,8,4,2,1,3,5,6,7,0,9. You want to end with: 9999,1,2,3,4,0,6,7,8,9.

    4. Start with slot 1,

    step a: exchange its contents with whatever slot contains the 0,
    -- this puts the x in slot 1
    9999,0,4,2,1,3,5,6,7,8,9

    step b: now exchange its contents with whatever slot contains the 1.
    You now have: 9999,1,4,2,0,3,5,6,7,8,9

    4. now do the same for slot 2, that's the recursive call, then slot 3, etc, except you skip slot 5 because that's supposed to end up with the empty.

    5. the end condition for your function is when next_slot > 9.

    Good luck, Al

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    60
    Thanks!!!!
    Usually I had no problems with my uni exercises,
    but recoursive functions and recoursive classes are
    desperating.
    Thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post your games here...
    By Hammer in forum Game Programming
    Replies: 132
    Last Post: 02-28-2013, 09:29 AM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. recoursive function
    By Mecnels in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2002, 05:27 PM