A row of a 2D array is a 1D array, and you can sort it the same way as you'd sort a 1D array: std::sort(std::begin(a[n]), std::end(a[n])); or even std::sort(a[n], a[n] + columns);
Sorting a column with a standard algorithm takes one extra step: to pass it to std::sort(), you need a pair of iterators such that the first iterator points at the element in the first row and the desired column, the second points at the element in the second row and the desired column, etc. With a 2D array, this means that the iterator skips as many elements as there are columns on every iteration. This is called "stride". Strided views are supported directly by std::valarray and by boost::multi_array, but for plain C-style 2D array you'd have to build it. Boost can do it easily: sort( boost::make_iterator_range(&a[0][0] + n, &a[0][0]+C*R) | strided(C) );