ruby 中想对数组中间的一段进行排序,我知道可以这样:
a[1..2] = a[1..2].sort!
但这样会有一次拷贝,出于效率原因希望不产生任何拷贝,直接在原数组上排序。
怪我咯2017-04-24 09:12:39
Sort only copies the structure of the array, and the contents of the array will not be copied, so the impact on performance is minimal.
What amount of data will make this code a performance bottleneck?
阿神2017-04-24 09:12:39
Using the sort method will regenerate a new array. You can use the array subscript to take out the elements for comparison, and just swap the positions