Sort a list of object identifiers: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: shorter alt)
Line 1,561: Line 1,561:


=={{header|Phix}}==
=={{header|Phix}}==
I would normally recommend a tagsort, but we can avoid the extra routine and tagset here.
This is a variation on a standard tagsort, but performed a bit more explicitly.
<lang Phix>sequence strings = {"1.3.6.1.4.1.11.2.17.19.3.4.0.10",
<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",
"1.3.6.1.4.1.11.2.17.5.2.0.79",
Line 1,590: Line 1,590:
"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"
"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>
</pre>