Jump to content

Sorting algorithms/Comb sort: Difference between revisions

Line 48:
 
=={{header|AutoHotkey}}==
<lang autohotkey></lang>List1 = 23,76,99,58,97,57,35,89,51,38,95,92,24,46,31,24,14,12,57,78
List2 = 88,18,31,44,4,0,8,81,14,78,20,76,84,33,73,75,82,5,62,70
Message box shows:
 
<pre></pre>
List2Array(List1, "MyArray")
CombSort("MyArray")
MsgBox, % List1 "`n" Array2List("MyArray")
 
List2Array(List2, "MyArray")
CombSort("MyArray")
MsgBox, % List2 "`n" Array2List("MyArray")
 
 
 
;---------------------------------------------------------------------------
CombSort(Array) { ; CombSort of Array %Array%, length = %Array%0
;---------------------------------------------------------------------------
Gap := %Array%0
While Gap > 1 Or Swaps {
If (Gap > 1)
Gap := 4 * Gap // 5
i := Swaps := False
While (j := ++i + Gap) <= %Array%0 {
If (%Array%%i% > %Array%%j%) {
Swaps := True
%Array%%i% := (%Array%%j% "", %Array%%j% := %Array%%i%)
}
}
}
}
 
 
 
;---------------------------------------------------------------------------
List2Array(List, Array) { ; creates an array from a comma separated list
;---------------------------------------------------------------------------
global
StringSplit, %Array%, List, `,
}
 
 
 
;---------------------------------------------------------------------------
Array2List(Array) { ; returns a comma separated list from an array
;---------------------------------------------------------------------------
Loop, % %Array%0
List .= (A_Index = 1 ? "" : ",") %Array%%A_Index%
Return, List
}</lang>
Message (1) box shows:
<pre>23,76,99,58,97,57,35,89,51,38,95,92,24,46,31,24,14,12,57,78
12,14,23,24,24,31,35,38,46,51,57,57,58,76,78,89,92,95,97,99</pre>
Message (2) box shows:
<pre>88,18,31,44,4,0,8,81,14,78,20,76,84,33,73,75,82,5,62,70
0,4,5,8,14,18,20,31,33,44,62,70,73,75,76,78,81,82,84,88</pre>
 
=={{header|C}}==
138

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.