Jump to content

Sorting algorithms/Strand sort: Difference between revisions

Line 3:
{{Wikipedia|Strand sort}}
Implement the [[wp:Strand sort|Strand sort]]. This is a way of sorting numbers by extracting shorter sequences of already sorted numbers from an unsorted list.
 
=={{header|AutoHotkey}}==
{{works with|AutoHotkey_L}}
<lang AutoHotkey>
string =
(
-2 0 -2 5 5 3 -1 -3 5 5 0 2 -4 4 2
)
string2 := string
Loop
{
loop, parse, string, %A_space%
{
list := 1 = A_index ? A_loopfield : list
StringSplit, k, list, %A_space%
if ( k%k0% <= A_loopfield ) && ( l != "" ) && ( A_index != 1 )
list := list . " " . A_loopfield
 
if ( k%k0% > A_loopfield )
list := A_loopfield . " " . list , index++
l := A_loopfield
}
if ( index = 0 )
{
MsgBox % "unsorted:" string2 "`n Sorted:" list
exitapp
}
string := list, list = "", index := 0
}
 
esc::ExitApp</lang>outout<lang>
unsorted:-2 0 -2 5 5 3 -1 -3 5 5 0 2 -4 4 2
Sorted:-4 -3 -2 -2 -1 0 0 2 2 3 4 5 5 5 5</lang>
 
=={{header|C}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.