Jump to content

Sort a list of object identifiers: Difference between revisions

→‎{{header|REXX}}: used OUT template, simplified program, elided the use of finding the maximum width number in the OID.
(→‎{{header|REXX}}: used OUT template, simplified program, elided the use of finding the maximum width number in the OID.)
Line 442:
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).*/
$= 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.*/
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 $. */
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.*/
say copies('░', 79) /*display fence, separate before &after*/
call norma 1; call bSort #; call norma 0 /*expand all/sort/shrink the internal OID numbers. '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. */
exit /*stick a fork in it, we're all done. */
Line 469 ⟶ 462:
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. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
norma: arg LZ; do j=1 for #; x=translate(@.j, , .); y=left(.,left(x,1)==.) /*construct YX version. */
if y do k==.1 thenfor x=substrwords(x, 2); _=word(x, k) /*get a number in /*X. have leading dot?*/
if LZ then y=y right(_,30,0); do else while x\y=='';y parse var x z "." x_+0 /*extractadd/elide the number.leading 0's*/
end /*k*/ if LZ then y=y || right(z, w, 0). /*added leading 0's ? /*adjust number, append*/
@.j = translate( else y=space(y), ||., z+0' ') || . /*elide " " reconstitute number. */
end end /*whilej*/ /* [↑] Y is now adj /*LZ: Leading Zero(es).*/
return @.j=strip(y, 'T', .) /*use── ─ ─ new Y version.*/
end /*j*/ /*LZ: Leading Zero(es)*/
return /*── ─ ─ */
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: do sa=1 for #; say right("OID number",20) right(sa,L) arg(1) @.sa; end; return</lang>
'''{{out|output''' |text=&nbsp; when using the (internal) default numbersinput:}}
<pre>
OID number 1 before sort ───► 1.3.6.1.4.1.11.2.17.19.3.4.0.10
Cookies help us deliver our services. By using our services, you agree to our use of cookies.