nag_sort_intvec_rank (m01db) uses a variant of list-merging, as described on pages 165–166 in
Knuth (1973). The function takes advantage of natural ordering in the data, and uses a simple list insertion in a preparatory pass to generate ordered lists of length at least
. The ranking is stable: equal elements preserve their ordering in the input data.
Not applicable.
This example reads a list of integers and ranks them in descending order.
function m01db_example
fprintf('m01db example results\n\n');
iv = [int64(34) 44 89 64 69 69 23 1 999 65 22 76];
m1 = int64(1);
order = 'Descending';
[irank, ifail] = m01db(iv, m1, order);
fprintf(' Data Ranks\n\n');
for i = 1:numel(iv)
fprintf('%7d%7d\n',iv(i),irank(i));
end