Sort a list of object identifiers: Difference between revisions

→‎{{header|REXX}}: made more idiomatic by using a subroutine for generating the array, added/changed comments and whitespace, allowed for a larger identifier.
(→‎Haskell – Data.Text: Reduced an expression, slightly)
(→‎{{header|REXX}}: made more idiomatic by using a subroutine for generating the array, added/changed comments and whitespace, allowed for a larger identifier.)
Line 634:
This REXX version supports negative integers in the OID.
<lang rexx>/*REXX program performs a sort of OID (Object IDentifiers ◄── used in Network data).*/
$= 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 , /* ◄──┼─◄─ six OID numbers (as a list).*/
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 /* ◄──┘ */
#=words($)call gen /*#:generate an thearray number(@.) of OIDs infrom the $ listOIDs.*/
do i=1 for #; @.i=word($,i) /*build the @ array from each word in $*/
end /*i*/
L=length(#) /*length of the number of words in $.*/
call show 'before sort ───► ' /*display the @ array before sorting.*/
say copies('░', 79) /*display fence, separate before &after*/
call normaadj 1; call bSort #; call normaadj 0 /*expand/sort/shrink the internal OID's*/
call show ' after sort ───► ' /*display the @ array after sorting. */
exit /*stick a fork in it, we're all done. */
Line 652 ⟶ 649:
bSort: procedure expose @.; parse arg n; m=n-1 /*N: is the number of @ array elements.*/
do m=m for m by -1 until ok; ok=1 /*keep sorting the @ array until done. */
do j=1 for m; _=j+1; if @.j>@._ then parse value @.j @._ 0 with @._ @.j ok
end /*j*/ /* [↑] swap two out─of─order elements.*/
end /*m*/; return /* [↑] use a simple bubble sort. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
normagen: arg LZ #=words($); L=length(#); do ji=1 for #; x=translate(@.ji=word($, , .i); y= /*constructend; X version. */return
do i=1 for #; @.i=word($,i) /*buildlength of the @ arraynumber from eachof wordwords in $.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
adj: arg LZ; do j=1 for #; x=translate(@.j, , .); y= /*construct X version. */
do k=1 for words(x); _=word(x, k) /*get a number in X. */
if LZ then y=y right(_,3090,0); else y=y _+0 /*add/elideadd│elide leading 0's*/
end /*k*/ /*adjust number, append*/
@.j = translate( space(y), ., ' ') /*reconstitute number. */
end /*j*/ /*LZ: Leading Zero(ess). */
return /*── ─ ─ */
/*──────────────────────────────────────────────────────────────────────────────────────*/