My alternative code is shown below:
Implementation in Redcode:
org innerThis alternative implementation runs slightly faster than Ilmari's, at the cost of 1 extra line of code. The number of cycles in the worst case is 3n²-5, which also beats Gnome sort.
temp equ (outer-1)
outer mov.b x, y
mov.f q, p
inner slt {p, <p
y djn inner, #LENGTH-1
jmz next, y
mov @p, temp
p mov FIRST+LENGTH, FIRST+LENGTH-1
mov temp, *p
djn inner, y
x
next djn outer, #LENGTH-1
q dat FIRST+LENGTH-p, FIRST+LENGTH-p-1
No comments:
Post a Comment