Avatar of ubuntuguy
Flag for United States of America

asked on 

Smalltalk collections list to array

I have a list of employee objects in smalltalk. I'm trying to perform selection sort on this list to sort it by last name (lastName). Can you guide me in the right direction? I don't think I'm doing it right. This is how I create my method: I think I'm right since I dont get any errors... I just don't know how implement it to sort my list of employees by last name.
selectionSort: l to: r
| m il ir temp |
   (r > l) ifTrue: [
      m := self at: ((l + r) // 2).
      il := l.
      ir := r.
         [(self at: il) < m] whileTrue: [il := il + 1.].
         [(self at: ir) > m] whileTrue: [ir := ir - 1.].
         (il < ir) ifTrue: [
            " swap "
            temp := self at: il.
            self at: il put: (self at: ir).
            self at: ir put: temp.
      ] doUntil: [il >= ir.].
      self selectionSort: l to: (il - 1).
      self selectionSort: (il + 1) to: r.

Open in new window

Programming Languages-OtherJavaC

Avatar of undefined
Last Comment
Mick Barry

8/22/2022 - Mon