creating combinations of array values - recursion??

This is a discussion on creating combinations of array values - recursion?? within the C Programming forums, part of the General Programming Boards category; I have about 10 arrays (this number is a variable, can be more or less) with a certain number of ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    2

    creating combinations of array values - recursion??

    I have about 10 arrays (this number is a variable, can be more or less) with a certain number of elements in each (again number fo elements can vary for each array).

    I need to create all combinations of these arrays.
    A simple ex:

    Array1: 1,2
    Array2: 4
    Array3: 5,6

    Output should be

    1 4 5
    1 4 6
    2 4 5
    2 4 6


    Would recusion be a good way of doing it?
    Or is there any other approach?

  2. #2
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Recursion can work if you can come up with a base function that can be implemented to traverse your arrays to determine the unique combinations there of.

    What appears, from the surface, is that you have/need some sort of graphing algorithm that can be put together in how these arrays relate to one another. This will determin if array1 element 1 can be related/connected in some fashion to array3 element 6.

    A simple means of using for loops can to the job.

    The big question is what have you come up with as far as code?

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Recursion is a very easy way of doing this. Though a loop seems like an even easier and more stack friendlier method.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  3. Replies: 12
    Last Post: 04-12-2009, 06:49 PM
  4. Eliminating duplicate values from a 20x2 array
    By desipunjabi in forum C Programming
    Replies: 2
    Last Post: 10-29-2005, 10:11 PM
  5. Creating array from data file...
    By Crankit211 in forum C Programming
    Replies: 2
    Last Post: 12-06-2001, 09:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21