Sorting algorithms/Strand sort: Difference between revisions

m (→‎{{header|Sidef}}: modified the code to work with the latest version of Sidef)
Line 1,039:
Before The quick brown fox jumps over the lazy dog
After The brown dog fox jumps lazy over quick the</pre>
 
=={{header|Phix}}==
Copy of [[Sorting_algorithms/Strand_sort#Euphoria|Euphoria]]
<lang Phix>function merge(sequence left, sequence right)
sequence result = {}
while length(left)>0 and length(right)>0 do
if left[$]<=right[1] then
exit
elsif right[$]<=left[1] then
return result & right & left
elsif left[1]<right[1] then
result = append(result,left[1])
left = left[2..$]
else
result = append(result,right[1])
right = right[2..$]
end if
end while
return result & left & right
end function
function strand_sort(sequence s)
integer j
sequence result = {}
while length(s)>0 do
j = length(s)
for i=1 to length(s)-1 do
if s[i]>s[i+1] then
j = i
exit
end if
end for
result = merge(result,s[1..j])
s = s[j+1..$]
end while
return result
end function</lang>
 
=={{header|PHP}}==
7,794

edits