Stabilizing the standard library qsort?

No, you cannot rely on that unfortunately. Let’s assume you have the array (two fields in each record used for checking but only first field used for sorting): B,1 B,2 A,3 A non-stable sort may compare B,1 with A,3 and swap them, giving: A,3 B,2 B,1 If the next step were to compare B,2 with … Read more

Stable accumarray in MATLAB

We can use sortrows as a preprocessing step to sort the indices and corresponding values first, as its documentation states: SORTROWS uses a stable version of quicksort. As the subscripts in subs should be sorted with respect to their linear indices, we need to sort them in reverse lexicographic order. This can be achieved by … Read more

What is the stability of the Array.sort() method in different browsers?

As of ES2019, sort is required to be stable. In ECMAScript 1st edition through ES2018, it was allowed to be unstable. Simple test case (ignore the heading, second set of numbers should be sequential if the engine’s sort is stable). Note: This test case doesn’t work for some versions of Chrome (technically, of V8) that … Read more