I trying to do my HW, and stuck.
Here is my problem:
I am given two sets: let set1 {a b c} and set2{1 2 3 4 5}
and I need to make 1-1 function. meaning that every element in Set1 need to map to only one element in set2 My program gives me right answers BUT it is good only if there is only 3 elements in 1st set, what if there is 4 or 5? I need to create recursive function but I and not sure how.
Enter number of elements in sets(separated by space): 3 5
Enter set A (separated by space): a b c
Enter set B (separated by space): 1 2 3 4 5
The 1-1 function has 60 elements.
{(a,1), (b,2), (c,3)}
{(a,1), (b,2), (c,4)}
{(a,1), (b,2), (c,5)}
{(a,1), (b,3), (c,2)}
{(a,1), (b,3), (c,4)}
{(a,1), (b,3), (c,5)}
.......
{(a,5), (b,2), (c,1)}
{(a,5), (b,2), (c,3)}
{(a,5), (b,2), (c,4)}
{(a,5), (b,3), (c,1)}
{(a,5), (b,3), (c,2)}
{(a,5), (b,3), (c,4)}
{(a,5), (b,4), (c,1)}
{(a,5), (b,4), (c,2)}
{(a,5), (b,4), (c,3)}
my function that does element distribution in c++
void getOneToOne(vector <string> &oneTone, vector <string> set1, vector <string> set2){
for (size_t i = 0; i < set2.size(); i++)
{
for (size_t k = 0; k < set2.size(); k++)
{
if (k != i)
{
for (size_t j = 0; j < set2.size(); j++)
{
if (j != i && k != j)
{
string temp;
temp = "{(" + set1[0] + "," + set2[i] + "), (" + set1[1] + "," + set2[k] + "), (" + set1[2] + "," + set2[j] + ")}";
oneTone.push_back(temp);
}
}
}
}
}
}