F
F
Fardeen Drag2018-10-21 13:39:56
C++ / C#
Fardeen Drag, 2018-10-21 13:39:56

How to reverse array columns?

How can you reverse the columns of a two-dimensional array?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2018-10-22
Yazovskikh @unepic

Since the question is in the topic about C ++, then you are probably not interested in raw arrays and raw loops. Then you can do this:

#include <algorithm>
std::vector<std::vector<int>> arr = {{0,1,2,3},{0,1,2,3},{0,1,2,3}};
std::for_each(arr.begin(), arr.end(), [](auto& row){ std::reverse(row.begin(), row.end()); });

M
Maxim Moseychuk, 2018-10-21
@fshp

Can be done with loops and brain drops.
If some blas is used to work with two-dimensional arrays, then most likely there is already a ready-made function for this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question