Skip to content
Next Next commit
Simple bubble sort in Smalltalk.
  • Loading branch information
Neverik committed Oct 3, 2018
commit 891473af45f6b714049d9d08d2150461c2b09b9e
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ Trashtalk
Cyrus Burt
<br>
Patrik Tesarik
<br>
<br>Neverik
2 changes: 2 additions & 0 deletions contents/bubble_sort/bubble_sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ Trust me, there are plenty of more complicated algorithms that do precisely the
[import, lang:"nim"](code/nim/bubble_sort.nim)
{% sample lang="f90" %}
[import, lang:"fortran"](code/fortran/bubble.f90)
{% sample lang="st" %}
[import, lang:"smalltalk"](code/smalltalk/bubble.st)
{% endmethod %}

<script>
Expand Down
17 changes: 17 additions & 0 deletions contents/bubble_sort/code/smalltalk/bubble.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
bubbleSort
"Bubble sort for an array."

| len swapper thisElem nextElem nextIndex |
len := self size.
1 to: len - 1 do: [ :iteration |
1 to: len - 1 do: [ :thisIndex |
thisElem := self at: thisIndex.
nextIndex := thisIndex + 1.
nextElem := self at: nextIndex.
(thisElem > nextElem) ifTrue: [
swapper := nextElem.
self at: nextIndex put: thisElem.
self at: thisIndex put: swapper.
]
]
]
Loading