Ticket #193: shell-sorts.patch
File shell-sorts.patch, 1.7 KB (added by hopscc, 15 years ago) |
---|
-
HowTo/290-TranslatePseudoCodeToCobra1.cobra
195 195 result.addRange(.quickSort(more)) 196 196 return result 197 197 198 def shellSort(list) as dynamic 199 test 200 .testSort(ref .shellSort) 201 body 202 top = list.count 203 nExchg = false 204 gap = Decimal.toInt32(top/2) 205 post while gap > 0 206 post while nExchg # exchanges happened 207 nExchg = false 208 for i in 0 : top - gap 209 value = list[i] to ! 210 if value > list[i+gap] 211 list[i] = list[i+gap] 212 list[i+gap] = value 213 nExchg = true 214 gap = (gap/2) to int 215 return list 216 198 217 def main 199 218 .quickSort([1,2,3,4]) -
HowTo/292-TranslatePseudoCodeToCobra2.cobra
188 188 result.addRange(.quickSort(more)) 189 189 return result 190 190 191 def shellSort(list as IList) as dynamic 192 test 193 .testSort(ref .shellSort) 194 body 195 top = list.count 196 nExchg = false 197 gap = (top/2) to int 198 post while gap > 0 199 post while nExchg # exchanges happened 200 nExchg = false 201 for i in 0 : top - gap 202 value = list[i] to dynamic 203 if value > list[i+gap] 204 list[i] = list[i+gap] 205 list[i+gap] = value 206 nExchg = true 207 gap = (gap/2) to int 208 return list 209 191 210 def main 192 211 .quickSort([1,2,3,4])