Get I do not know how to use nested x for loops in addition to data of X sets all the possibilities I Do this because I do not know the value of X, which makes it very difficult for the number of loops, which is not equal to the number of loops required.
I have to say:
A: 1,2,3,4B: 2,4,65,2C: 1,3,2D: 2, 8 and I wanted to get to each combination of one item from each group (in my code, std :: vector & lt; myclass & gt; ), how would I do this? Can someone post me a normal pseudocode, on which I can do this?
If you do not know you have many 'groups', I think you have some of these Is there a collection of? That is, the array / vector of all your vectors?
If so, here's the general idea is to work
void repeated all Kombineshn (array_of_groups, current_group_index, temp_result, callback_function) Current_group {temp_result [current_group_index] in = elements For each element {current_group = array_of_groups [current_group_index] if current_group_index and gt; 0 iterate AllCombinations (array_of_groups, current_group_index-1, temp_result, callback_function) and callback_function (temp_result)}} will be added in some fashion: repeated all intercourse (my_groups, my_groups.length-1, a new vector [my_groups.length], and amp ; do_something_with_array) a basic explanation of what is happening: when you call the function, then it began to walk through each item on the 'top' group (final) in Srni_of_smuhon If more groups are beyond 'Top', then it will call the same function Current objects will pass so far, and it will ask to see the next group.
This next level is going down through each item, and behave in the same way it continues till you go down to the group, instead of calling at the other level , It will store all the results in your callback function, which they will use.
When the level below is gone through all the objects, it will return to the next level, which is still in 'each' loop. The next level will go to the next item above, and call at the bottom level, which will start from the beginning, it continues till the 'top' level also goes through each item.
This is pseudocode, show changes in specification depending on your language declared "temporary results and allocated up-front array (as I pseudocode may be), or a stack Which may be pushed before each recurring call, and then popped up, or it's an array / vector that you copy and add before each recursive call. You can also have a link list, with each node stored in the stack frame for each function call, and you have to pass the indicator of 'parent' to the next level.
If you have a specific thing that you want to do, then you can change 'callback function' with that specific thing or, if your language allows it, then you can get it by using the iterator / generator , And it should be 'callback'.
If you really hate the recursive code, then you can write the same thing as a loop, but it is very easy to write as a recurring function.
Comments
Post a Comment