3 function quicksort(a
,r
,s
)
4 if s
<=r
then return end
5 local v
, i
, j
= a
[r
], r
, s
+1
7 i
=i
+1; while a
[i
]<v
do i
=i
+1 end
8 j
=j
-1; while a
[j
]>v
do j
=j
-1 end
11 a
[i
],a
[j
]=a
[j
],a
[i
] -- undo last swap
17 function selectionsort(a
,n
)
22 if a
[j
]>a
[m
] then m
=j
end -- reverse sort
25 a
[i
],a
[m
]=a
[m
],a
[i
] -- swap a[i] and a[m]
36 if x
[i
] then write(",") end
41 x
={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}
43 n
=1 while x
[n
] do n
=n
+1 end -- count elements
44 x
[0]="A" x
[n
]="Z" -- quicksort need sentinels
49 show("after quicksort",x
)
52 show("after reverse selection sort",x
)