Welcome to the Monastery | |
PerlMonks |
Re^6: move all 0s in an array to the beginning keeping other elements order sameby davido (Cardinal) |
on May 05, 2014 at 06:35 UTC ( [id://1085003]=note: print w/replies, xml ) | Need Help?? |
What I didn't state clearly in my previous comment is this: In the old days, Perl's sort used a QuickSort algorithm, and it was swapped out, replaced by a Merge Sort starting (if my memory serves) with Perl 5.8. This swap in the implementation of Perl's "sort" was done primarily to avoid the potential for QuickSort to go quadratic on some inputs. A secondary effect was that it provided a stable sort. However unlikely it is that Perl would ever switch again, and this time to an unstable sort, the fact that modern Perls have a stable sort is still just an implementation detail. By specifying "use sort 'stable'", you are making a declaration of what semantics you require, leaving nothing to chance. Additionally, it signals to a future maintainer that this code would not fly if deprived of a stable sort. Dave
In Section
Seekers of Perl Wisdom
|
|