Sort using a custom comparator: Difference between revisions

Line 1,886:
case 0
{
aj$=lcase$(a$(j))
if aj$>lx$ then exit
if aj$=lx$ then if a$(j)<=x$ then exit
i++
Swap a$(i),a$(j)
Line 1,924:
}
Checkit
</lang>
 
ForStringsSpecial can be coded used a Compare()(aj$, lx$). See the use of break to break cases in select cases.
Any case in Select case may have one statement (if then is one statement), or a block of code. We can leave a case with a blank line after, a one statement line, or a block of code, or a case statement. A break statement break cases, so all code executed, until a continue found, to exit from Select (next statement after End Select). We use a sub to make two statements as one.
 
<lang M2000 Interpreter>
Group Quick {
Module ForStringsSpecial {
.partition<=lambda-> {
Read &a$(), p, r : i = p-1 : x$=a$(r) :lx$=lcase$(x$) : k=len(x$)
For j=p to r-1 {
m=len(a$(j))
select case compare(m, k)
case 0
{
aj$=lcase$(a$(j))
\\ in Case the Break statement execute all cases until a case has a Continue
select case compare(aj$, lx$)
case 0
if a$(j)>x$ then break
Case 1
swapit()
End Select
}
case 1
swapit()
End Select
} : Swap a$(i+1), a$(r) : Push i+2, i
Sub swapit()
i++:Swap a$(i),a$(j)
End Sub
}
}
}
</lang>
 
Anonymous user