Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,24 @@
OrderedCollection extend [
stoogeSortFrom: i to: j [
(self at: j) < (self at: i)
ifTrue: [ self swapElement: i with: j ].
j - i > 1
ifTrue: [
|t| t := (j - i + 1)//3.
self stoogeSortFrom: i to: (j-t).
self stoogeSortFrom: (i+t) to: j.
self stoogeSortFrom: i to: (j-t)
]
]
stoogeSort [ self stoogeSortFrom: 1 to: (self size) ]
swapElement: i with: j [
|t| t := self at: i.
self at: i put: (self at: j).
self at: j put: t
]
].
|test|
test := #( 1 4 5 3 -6 3 7 10 -2 -5) asOrderedCollection.
test stoogeSort.
test printNl.

View file

@ -0,0 +1,15 @@
stoogesort := [:L :i :j |
(L at:i) > (L at:j) ifTrue:[
L swap:i with:j
].
(j - i + 1) > 2 ifTrue:[
t := ((j - i + 1) / 3) floor.
stoogesort value:L value:i value:j-t.
stoogesort value:L value:i+t value:j.
stoogesort value:L value:i value:j-t.
].
].
a := #(1 4 5 3 -6 3 7 10 -2 -5 7 5 9 -3 7) copy.
stoogesort value:a value:1 value:a size.
Transcript showCR:a