Sort a list of object identifiers: Difference between revisions

No edit summary
Line 616:
1.3.6.1.4.1.11150.3.4.0.1
</pre>
===Without use Internal Sort===
We use a stack (a linked list) to save numbers, and a function to check piece by piece for "larger than" only
 
piece$(a$,".")(i) works from 0
 
piece$(a$,".", i) works from 1
 
piece$(a$,".") export a pointer to an array with each piece on it
 
 
<lang M2000 Interpreter>
LT=lambda (a$, b$)->{
def i
do {
m$=piece$(a$,".")(i)
n$=piece$(b$,".")(i)
i++
} until n$="" or m$="" or m$<>n$
if n$="" then =m$<>"":exit
if m$="" then =False:exit
=val(m$)>val(n$)
}
Stack new {
\\ data push to end of stack (we use it as FIFO)
data "1.3.6.1.4.1.11.2.17.19.3.4.0.10"
data "1.3.6.1.4.1.11.2.17.5.2.0.79"
data "1.3.6.1.4.1.11.2.17.19.3.4.0.4"
data "1.3.6.1.4.1.11150.3.4.0.1"
data "1.3.6.1.4.1.11.2.17.19.3.4.0.1"
data "1.3.6.1.4.1.11150.3.4.0"
If Stack.Size>1 then {
Do {
addone=0
For i=1 to Stack.Size-1 {
\\ if peek item i > peek item i+1 then get i+1 to top, and send to i
\\ stack is a linked list, so moving items done with pointers only
if Lt(stackitem$(i), stackitem$(i+1)) then Shift i+1 : ShiftBack i : addone--
}
} Until Not addone
}
While not empty {
Print Letter$
}
}
</lang>
 
Using a function which split pieces one time. We have to insert one more item, by append a "." to a$ and b$
<lang M2000 Interpreter>
LT=lambda (a$, b$)->{
def i=-1
dim Base 0, a$(), b$()
a$()=piece$(a$+".", ".")
b$()=piece$(b$+".", ".")
do {
i++
} until a$(i)="" or b$(i)="" or a$(i)<>b$(i)
if b$(i)="" then =a$(i)<>"":exit
if a$(i)="" then =False:exit
=val(a$(i))>val(b$(i))
}
</lang>
 
=={{header|Perl}}==
Anonymous user