Sort a list of object identifiers: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring the hard way, phix/basics) |
Alpha bravo (talk | contribs) (Added AutoHotkey) |
||
Line 576: | Line 576: | ||
1.3.6.1.4.1.11150.3.4.0 |
1.3.6.1.4.1.11150.3.4.0 |
||
1.3.6.1.4.1.11150.3.4.0.1</pre> |
1.3.6.1.4.1.11150.3.4.0.1</pre> |
||
=={{header|AutoHotkey}}== |
|||
<lang AutoHotkey>; based on http://www.rosettacode.org/wiki/Sorting_algorithms/Quicksort#AutoHotkey |
|||
OidQuickSort(a, Delim:=".", index:=1){ |
|||
if (a.Count() <= 1) |
|||
return a |
|||
Less := [], Equal := [], More := [] |
|||
Pivot := StrSplit(a[1], Delim)[index] |
|||
for k, v in a |
|||
{ |
|||
x := StrSplit(v, Delim)[index] |
|||
if (x < Pivot) |
|||
less.InsertAt(1, v) |
|||
else if (x > Pivot) |
|||
more.InsertAt(1, v) |
|||
else |
|||
Equal.InsertAt(1, v) |
|||
} |
|||
Equal := OidQuickSort(Equal, Delim, index+1) |
|||
Less := OidQuickSort(Less) |
|||
Out := OidQuickSort(More) |
|||
if (Equal.Count()) |
|||
Out.InsertAt(1, Equal*) ; InsertAt all values of Equal at index 1 |
|||
if (Less.Count()) |
|||
Out.InsertAt(1, Less*) ; InsertAt all values of Less at index 1 |
|||
return Out |
|||
}</lang> |
|||
Examples:<lang AutoHotkey>a := ["1.3.6.1.4.1.11.2.17.19.3.4.0.10" |
|||
,"1.3.6.1.4.1.11.2.17.5.2.0.79" |
|||
,"1.3.6.1.4.1.11.2.17.19.3.4.0.4" |
|||
,"1.3.6.1.4.1.11150.3.4.0.1" |
|||
,"1.3.6.1.4.1.11.2.17.19.3.4.0.1" |
|||
,"1.3.6.1.4.1.11150.3.4.0"] |
|||
for k, v in OidQuickSort(a) |
|||
Out .= "`n" v |
|||
MsgBox % Out |
|||
return</lang> |
|||
{{out}} |
|||
<pre>1.3.6.1.4.1.11.2.17.5.2.0.79 |
|||
1.3.6.1.4.1.11.2.17.19.3.4.0.1 |
|||
1.3.6.1.4.1.11.2.17.19.3.4.0.4 |
|||
1.3.6.1.4.1.11.2.17.19.3.4.0.10 |
|||
1.3.6.1.4.1.11150.3.4.0 |
|||
1.3.6.1.4.1.11150.3.4.0.1 |
|||
</pre> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |