On Mon, Jan 28, 2013 at 2:34 PM, Brian Schott <[email protected]> wrote:
> I realize there are approaches like Raul and Devon are proposing that
> use 2D array indexing and require two array resequencing, but I was
> hoping to do both steps at once arithmetically to resequence the
> single index list to achieve efficiency.

What do you mean by efficiency?

Time?

Space?

Code?

Forum? (But I'll stop trying to move this to chat, I guess...)

Anyways, here's an in-place implementation:

int * whatever(int n, int * r) {
        for (int j= 0; j < n; j++)
                for (int k= 0; k < n; k++) {
                        int i1= j+n*k;
                        int i2= j*n-(1+k);
                        if (i1 < i2) {
                                int t= r[i1];
                                r[i1]= r[i2];
                                r[i2]= t;
                        }
                }
        return r;
}

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to