Question: I am trying to do some DNA analysis in C++.
I have a 2D array of characters containing DNA sequences. `char input[n][m];`

Now based on the DNA pattern, I do some processing on the input array and find a new sequence for this pattern.

Let say the original sequence was `1,2,3,4,5,6`. These are the 6 DNA's (rows of the 2D array)

After processing i get the order as `1,6,2,4,3,5`. Then how do I rearrange the original input array as per this sequence. That is, the first row of input should now have 1st DNA, 2nd row should now have the DNA which was sixth in the original array and so on. 

```
 int main()

{

using namespace std;
char input[t][l] = {    {'A','A','A','T','C','A','G','T','A'},
                        {'A','T','T','A','C','T','G','C','A'},
                        {'A','G','C','T','A','C','T','G','C'},
                        {'A','T','T','A','C','T','G','C','A'},
                        {'A','G','C','T','A','C','T','G','C'}

                 };

// SOME PROCESSING

Here output array has the elements ={1,6,2,4,3,5}

  for (int i = 0; i<t; i++)
  {
  cout << output[i] << " ";
  }  
}

```

Any ideas how to change the addresses in the memory so as re-order the original array?

Answer: 
This would only move around pointers:

```
char input[5][9] = {    {'A','A','A','T','C','A','G','T','A'},
                        {'A','T','T','A','C','T','G','C','A'},
                        {'A','G','C','T','A','C','T','G','C'},
                        {'A','T','T','A','C','T','G','C','A'},
                        {'A','G','C','T','A','C','T','G','C'}
                 };

char* output[5];
output[0] = input[3];
output[1] = input[2];
output[2] = input[4];

char test = output[1][3];

```
Personally I would use `vector<string> input`

and then

```
vector<double> output_list (t,0); // length t, initialized to 0

// assign the values of output_list

for (int i = 0; i<t; i++)
{
cout << input[output_list[i]] << " ";
}

```

Please note that this solution does not require additional memory (there is not a second 2D array) nor additional computation time (you do not swap the data, you simply call the part that you need)

If you instead absolutely need to re-order the array (as I notice in your comments), you may `swap(input[i],input[j])` as many times as needed.