Sorting algorithms/Quicksort: Difference between revisions
m
→{{header|AppleScript}}: →Straightforward: Tidied.
m (→{{header|AppleScript}}: →Straightforward: Tidied.) |
|||
Line 896:
===Straightforward===
Emphasising clarity,
<lang applescript>
-- Algorithm: S.A.R. (Tony) Hoare, 1960.
on quicksort(theList, l, r) -- Sort items l thru r of theList.▼
if (listLength < 2) then return
▲on quicksort(theList, l, r)
-- Script object containing the list as a property (to allow faster references to its items)
-- and the recursive subhandler.
script o
property lst : theList
Line 912 ⟶ 918:
set j to r
repeat until (i > j)
set
repeat while (
set i to i + 1
set
end repeat
set
repeat while (
set j to j - 1
set
end repeat
if (j > i) then
set my lst's item i to
set my lst's item j to
else if (i > j) then
exit repeat
Line 940 ⟶ 946:
end script
▲ if (listLength > 1) then
▲ -- Convert negative and/or transposed range indices.
▲ if (l < 0) then set l to listLength + l + 1
▲ if (r < 0) then set r to listLength + r + 1
▲ if (l > r) then set {l, r} to {r, l}
return -- nothing
end quicksort
property sort : quicksort
--
local aList
set aList to {28, 9, 95, 22, 67, 55, 20, 41, 60, 53, 100, 72, 19, 67, 14, 42, 29, 20, 74, 39}
sort(aList, 1, -1) -- Sort
return aList</lang>
{{output}}
<lang applescript>{9, 14, 19, 20, 20, 22, 28, 29, 39, 41, 42, 53, 55, 60, 67, 67, 72, 74, 95, 100}</lang>
=={{header|Arc}}==
<lang Arc>(def qs (seq)
|