Code: Select all
#macro combsort(array,begin,finish,dot,direction)
Scope
Var size=(finish),switch=0,j=0
Dim As Single void=size
Do
void=void/1.3: If void<1 Then void=1
switch=0
For i As Integer =(begin) To size-void
j=i+void
If array(i)dot direction array(j)dot Then
Swap array(i),array(j): switch=1
End If
Next
Loop Until switch =0 And void=1
End Scope
#endmacro
#macro printout(X)
?
print " Variable: ";
print #X
?
for n as integer=lbound(X) to lbound(X)+10
print x(n)
next n
?:?
print "..."
?:?
for n as integer=ubound(X)-10 to ubound(X)
print x(n)
next n
print "_________________________"
?
#endmacro
type mytype
as integer i
as string s
declare operator cast() as string
end type
union myunion
as single s(1 to 2)
declare operator cast() as string
end union
operator mytype.cast as string
var pad=30-len(str(i))
var fill=string(pad," ")
return str(i)+fill+s
end operator
operator myunion.cast as string
var pad=30-len(str(s(1)))
var fill=string(pad," ")
return str(s(1))+fill+str(s(2))
end operator
dim as integer size =250000
dim shared as double d(1 to size)
dim shared as string s(1 to size)
dim shared as mytype mt(1 to size)
dim shared as myunion mu(1 to size)
for n as integer=1 to size
d(n)=rnd*5-rnd*5
s(n)=str(3+rnd*10)
mt(n).i=rnd*500
mt(n).s=str(n)
mu(n).s(1)=rnd*100
mu(n).s(2)=rnd*1000
next n
print "values set"
dim as double t=timer
combsort(d,lbound(d),ubound(d),,<):print "double sorted"
combsort(s,lbound(s),ubound(s),,<):print "string sorted"
combsort(mt,lbound(mt),ubound(mt),.s,<):print "type mytype sorted, string part"
combsort(mu,lbound(mu),ubound(mu),.s(2),<):print "union myunion sorted, second field"
print
print "Time for four sorts of ";size;" = ";timer-t
print
printout(d)
printout(s)
printout(mt)
printout(mu)
print "done"
sleep