Comparator<T> c = new Comparator<T>()
{
@Override
public int compare(T o1, T o2)
{
if(o1 > o2) {
return 1;
} else if(o1 == o2) {
return 0;
} else {
return -1;
}
}
};
Collections.sort(items.subList(i, j), c);
use feature 'say';
@items = qw(0 1 2 3 a b c d e 9 10 11);
($i,$j) = (4,8);
$c = sub { $b cmp $a }; # sort alpha descending
say '# ', join ' ', @items;
@items[$i..$j] = sort $c @items[$i..$j];
say '# ', join ' ', @items;
# output:
# 0 1 2 3 a b c d e 9 10 11
# 0 1 2 3 e d c b a 9 10 11
@items = qw(0 1 2 3 a b c d e 9 10 11);
($i,$j) = (4,8);
$c = sub { $b cmp $a }; # sort alpha descending
say '# ', join ' ', @items;
@items[$i..$j] = sort $c @items[$i..$j];
say '# ', join ' ', @items;
# output:
# 0 1 2 3 a b c d e 9 10 11
# 0 1 2 3 e d c b a 9 10 11