Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Pascal

Idiom #290 Sort sublist

Sort the part of the list items from index i (included) to index j (excluded), in place, using the comparator c.

Elements before i and after j must remain unchanged.

FsiArraySort
ArraySort(@items[i], @items[j-1], elemsize, @c, @exchangeproc);

ArraySort is agnostic of the type of elements in the array it sorts, so it needs to know the size of an item (elemsize), as well as a reference to a procedure that exchanges items (exchangeproc).
items.setRange(i, j, items.sublist(i, j)..sort(c));

New implementation...
< >
programming-idioms.org