Download code - Download code - Bubble Sort
Back to Bubble_sort_(Smalltalk)
Download for Windows: single file, zip
Download for UNIX: single file, zip, tar.gz, tar.bz2
bubbleSort.st
1 !Array methodsFor: 'sorting' stamp:''! 2 bubbleSort: cmpFun 3 "Implementing Bubble sort with Smalltalk" 4 | i j tmp funResult | 5 i := self size. 6 [i > 0] 7 whileTrue: [j := 1. 8 [j <= i] 9 whileTrue: [funResult := cmpFun 10 value: (self at: i) 11 value: (self at: j). 12 funResult 13 ifTrue: [tmp := self at: i. 14 self 15 at: i 16 put: (self at: j). 17 self at: j put: tmp]. 18 j := j + 1]. 19 i := i - 1] 20 ! ! 21