# Thread: next_permutation on 2D array

1. ## next_permutation on 2D array

If I want all permutations of 1D array I have:
Code:
```#include <iostream>
#include <algorithm>

using namespace std;

main() {
int arr[4]={1,2,3,4};
for (int i=0; i<=23; i++) {
next_permutation(arr, arr+4);
for (int j=0; j<=3; j++) {
cout << arr[j] << ", ";
}
cout << endl;}

system("PAUSE");
return 0;}```
But if I have arr={{1,1,1}, {2,2,2}, {3,3,3}, {4,4,4}}, I don't know what should I put between brackets of next_permutation(), I tried next_permutation(arr[3], (arr+3)[3]), it does compile, but it does not permutate.
I'd like a solution to be:
1,1,1,2,2,2,3,3,3,4,4,4, (the order is not important)
1,1,1,2,2,2,4,4,4,3,3,3,
.
.
.
2,2,2,1,1,1,3,3,3,4,4,4,
etc.

2. I think it's not possible without some extra work.
next_permutation() works with a sequence and corresponding iterator. With 2D array you should have some 2D iterator which works with rows of that array. When swapping two rows, function should be able to get whole row at once with dereferencing using * operator. That is not possible with 2D array and ordinary int pointer, i.e. it is, but it does not work what you expect.

3. Can you post the full code with the 2D array and your attempt?

It looks like you don't need the values in each row permuted, right? If that is the case you should be able to do this.