Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

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.

items[i..j].sort_by(c);
items.setRange(i, j, items.sublist(i, j)..sort(c));
sub := items[i:j]
sort.Slice(sub, func(a, b int) bool {
	return c(sub[a], sub[b])
})
import functools
items[i:j] = sorted(items[i:j], key=functools.cmp_to_key(c))
items[i:j] = sorted(items[i:j], key=c)

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