Answer the question
In order to leave comments, you need to log in
How to iterate over paired combinations of objects in a linked list?
I can't figure out how to iterate over combinations of objects in a linked list from n to 2.
First, I started writing an algorithm on an array to make it easier. The result is a recursive function:
void combine(int index)
{
for (int i = index + 1; i < LENGTH; i++)
{
cout << arr[index] << " " << arr[i] << endl;
combine(i);
}
}
Answer the question
In order to leave comments, you need to log in
Something like this.
void pairs()
{
int arr[LENGTH] = {1, 2, 3, 4, 5};
for (int i = 0; i < LENGTH; i++)
{
for(int j = i + 1; j < LENGTH; j++)
{
cout << arr[i] << " " << arr[j] << endl;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question