Array.Sort fails sometimes if the sort algorithm is not stable. This is a better algorithm.