SORT_RC is a Python library which can sort a list of any kind of objects, using reverse communication (RC).
The program works by repeatedly asking the user to compare two items on the list. The user is free to carry out the comparison in the calling program, in any desired way.
A typical usage, to sort an array of 100 items, might look something like this:
n = 100 indx = 0 -- Indicates the beginning of a sort begin loop sort_rc ( n, indx, i, j, isgn ) if ( indx < 0 ) (Compare items I and J) if ( a(i) <= a(j) ) isgn = -1 else isgn = +1 else if ( 0 < indx ) (Swap items I and J) k = a(i) a(i) = a(j) a(j) = k else exit loop end loop
The original version of sort_rc() requires the use of several variables declared internally to the function, whose values must be preserved between calls. The conventions for such computations vary from language to language; moreover, this kind of approach means that a single copy of the function cannot handle multiple requests for computation that might arise, especially in parallel computations. For that reason, a revised function, called sort_safe_rc(), is available, which does not rely on hidden internal variables and may safely be used to manage multiple simultaneous sorts.
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
SORT_RC is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version and a Python version.
You can go up one level to the Python source codes.