for(int x = 0; x < <your array>.length; x++)
{
for(int y = 0; y < <your arracy.length; y++)
{
if(x==y) continue;
<output your permutations here>
console.print(string.format("[ {0} {1} ]", x, y));
}
}
for(int x = 0; x < <your array>.length; x++)
{
for(int y = 0; y < <your arracy.length; y++)
{
if(x==y) continue;
<output your permutations here>
console.print(string.format("[ {0} {1} ]", x, y));
}
}
int MAX = 10;
int SIZE = 6;
int array[SIZE];
for (int i = 0; i < SIZE; ++i)
{
array[i] = i+1; // initialize array from 1 to SIZE
}
bool done = false;
while (!done)
{
// Show the current one and set up for the next one
// The next two lines just output the array.
// Change them to whatever you need them to be to output the array
for(int i = 0; i < SIZE; ++i) printf("%d, ", array[i]);
printf("\n");
// Find the last element in the array that can be incremented
int index = SIZE-1;
int position_max = MAX;
while(index >= 0 && array[index] == position_max)
{
position_max--;
index--;
}
if (index < 0)
{
done = true;
}
else
{
// increment
array[index]++;
// reset the ones to the right
for(int i = index + 1; i < SIZE; ++i)
{
array[i] = array[i-1]+1;
}
}
}
for(int i = 0; i < SIZE; ++i)
print_to_screen(data_array[array[i]-1]);
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
22 Experts available now in Live!