2010年11月03日(水)
Differency of two sort results
テーマ:Smalltalk
Program:
---------------------------------------------
| anArray |
anArray := #('nakada' 'tomita' 'sato' 'yano' 'kitamura' 'yamada' 'kato' 'ono').
Transcript clear;show:'This output is the result of SortedCollection converted from Array.';cr.
(anArray asSortedCollection: [:a :b | a size <= b size]) do: [:each | Transcript show: each, ' ', each size; cr].
Transcript cr; show: 'This output is the result of the Array remains sorted.';cr.
(anArray sort: [:a :b | a size <= b size]) do: [:each | Transcript show: each, ' ', each size; cr].
Transcript cr;show: 'Those program is using same sorted block.Why two output is different?'
---------------------------------------------
Result:
---------------------------------------------
This output is the result of SortedCollection converted from Array.
ono 3
kato 4
sato 4
yano 4
nakada 6
yamada 6
tomita 6
kitamura 8
This output is the result of the Array remains sorted.
ono 3
sato 4
yano 4
kato 4
nakada 6
tomita 6
yamada 6
kitamura 8
Those program is using same sorted block.Why two output is different?
---------------------------------------------
---------------------------------------------
| anArray |
anArray := #('nakada' 'tomita' 'sato' 'yano' 'kitamura' 'yamada' 'kato' 'ono').
Transcript clear;show:'This output is the result of SortedCollection converted from Array.';cr.
(anArray asSortedCollection: [:a :b | a size <= b size]) do: [:each | Transcript show: each, ' ', each size; cr].
Transcript cr; show: 'This output is the result of the Array remains sorted.';cr.
(anArray sort: [:a :b | a size <= b size]) do: [:each | Transcript show: each, ' ', each size; cr].
Transcript cr;show: 'Those program is using same sorted block.Why two output is different?'
---------------------------------------------
Result:
---------------------------------------------
This output is the result of SortedCollection converted from Array.
ono 3
kato 4
sato 4
yano 4
nakada 6
yamada 6
tomita 6
kitamura 8
This output is the result of the Array remains sorted.
ono 3
sato 4
yano 4
kato 4
nakada 6
tomita 6
yamada 6
kitamura 8
Those program is using same sorted block.Why two output is different?
---------------------------------------------
















