16/04/21 13:03:18.17 5MDUs+Ed.net
>>433 Squeak Smalltalk (PositionableStream>#lastが無いのでPharoではNG。為念)
>>464 等を参考にループを >>462 よりシンプルにした版。
| simplerBubble |
simplerBubble := [:arr |
| stream |
stream := arr readStream position: 1.
[stream atEnd] whileFalse: [
stream last > stream next ifTrue: [
arr swap: stream position - 1 with: stream position.
stream position: 1
]
].
arr
].
simplerBubble value: (1 to: 10) asArray shuffled "=> #(1 2 3 4 5 6 7 8 9 10) "