Sort a list of object identifiers: Difference between revisions

m
m (→‎{{header|Phix}}: shorter alt)
Line 1,561:
 
=={{header|Phix}}==
IThis wouldis normallya recommendvariation on a standard tagsort, but weperformed can avoid the extra routinea andbit tagsetmore hereexplicitly.
<lang Phix>sequence strings = {"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",
Line 1,590:
"1.3.6.1.4.1.11150.3.4.0"
"1.3.6.1.4.1.11150.3.4.0.1"
</pre>
 
===alternative===
This is very similar to the above, but without using any tags/indexes at all.
<lang Phix>constant strings = {"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"}
 
function each(string original)
sequence sortable = apply(split(original,'.'),to_number)
return {sortable,original}
end function
-- sort on sortable, then use vslice to extract the originals:
printf(1,"%s\n",join(vslice(sort(apply(strings,each)),2),"\n"))</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>
 
7,795

edits