Sort a list of object identifiers: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: used OUT template, simplified program, elided the use of finding the maximum width number in the OID.) |
|||
Line 442: | Line 442: | ||
This REXX version supports the new and old format (supports a leading decimal point). |
This REXX version supports the new and old format (supports a leading decimal point). |
||
<lang rexx>/*REXX program performs a sort of OID (Object IDentifiers ◄── used in Network data).*/ |
<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($) /*#: the number of OIDs in the $ list.*/ |
#=words($) /*#: the number of OIDs in the $ list.*/ |
||
do i=1 for #; |
do i=1 for #; @.i=word($,i) /*build the @ array from each word in $*/ |
||
end /*i*/ |
end /*i*/ |
||
L=length(#) /*length of the number of words in |
L=length(#) /*length of the number of words in $.*/ |
||
a=translate($, , .); q=words(a) /*remove all the decimal points in $. */ |
|||
w=0 /*W: the widest decimal number in A. */ |
|||
do k=1 for q; w=max(w, length(word(a,k))) /*find width of widest number in A, */ |
|||
end /*k*/ /* (after decimal points have */ |
|||
/* been replaced with blanks). */ |
|||
call show 'before sort ───► ' /*display the @ array before sorting.*/ |
call show 'before sort ───► ' /*display the @ array before sorting.*/ |
||
say copies('░', 79) /*display fence, separate before &after*/ |
say copies('░', 79) /*display fence, separate before &after*/ |
||
call norma |
call norma 1; call bSort #; call norma 0 /*expand/sort/shrink the internal OID's*/ |
||
call bSort # /*invoke bubble sort to sort numbers. */ |
|||
call norma 0 /*shrink all the internal OID numbers. */ |
|||
call show ' after sort ───► ' /*display the @ array after sorting. */ |
call show ' after sort ───► ' /*display the @ array after sorting. */ |
||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
Line 469: | Line 462: | ||
do j=1 for m; _=j+1; if @.j>@._ then parse value @.j @._ 0 with @._ @.j ok |
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 /*j*/ /* [↑] swap two out─of─order elements.*/ |
||
end /*m*/; return |
end /*m*/; return /* [↑] use a simple bubble sort. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
norma: arg LZ; |
norma: 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(_,30,0); else y=y _+0 /*add/elide leading 0's*/ |
|||
end /*k*/ /*adjust number, append*/ |
|||
@.j = translate( space(y), ., ' ') /*reconstitute number. */ |
|||
end /*j*/ /*LZ: Leading Zero(es).*/ |
|||
return /*── ─ ─ */ |
|||
end /*j*/ /*LZ: Leading Zero(es)*/ |
|||
return /*── ─ ─ */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
show: do |
show: do a=1 for #; say right("OID number",20) right(a,L) arg(1) @.a; end; return</lang> |
||
{{out|output|text= when using the (internal) default input:}} |
|||
<pre> |
<pre> |
||
OID number 1 before sort ───► 1.3.6.1.4.1.11.2.17.19.3.4.0.10 |
OID number 1 before sort ───► 1.3.6.1.4.1.11.2.17.19.3.4.0.10 |