all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,33 @@
Smalltalk at: #gnomesort put: nil.
"Utility"
OrderedCollection extend [
swap: a with: b [ |t|
t := self at: a.
self at: a put: b.
self at: b put: t
]
].
"Gnome sort as block closure"
gnomesort := [ :c |
|i j|
i := 2. j := 3.
[ i <= (c size) ]
whileTrue: [
(c at: (i-1)) <= (c at: i)
ifTrue: [
i := j copy.
j := j + 1.
]
ifFalse: [
c swap: (i-1) with: i.
i := i - 1.
i == 1
ifTrue: [
i := j copy.
j := j + 1
]
]
]
].

View file

@ -0,0 +1,9 @@
|r o|
r := Random new.
o := OrderedCollection new.
1 to: 10 do: [ :i | o add: (r between: 0 and: 50) ].
gnomesort value: o.
1 to: 10 do: [ :i | (o at: i) displayNl ].