' Floats Array Tools.BM
''OPTION _EXPLICIT
'' Build a set of Floats Array tools for handling Tomaaz challenge
'' Build Floats Array Tools.bm from these
'RANDOMIZE TIMER
'DIM i AS LONG, test$, TomaazTest$
'TomaazTest$ = "120 135 345 345 1890 12 120 12 135 712 78 120"
''FOR i = 1 TO 500
'' test$ = test$ + LTRIM$(STR$(INT(RND * 100))) + " "
''NEXT
''test$ = RTRIM$(test$)
'test$ = TomaazTest$
'PRINT "Test string: "; test$
'REDIM temp(0) AS _FLOAT
'Split2Floats test$, " ", temp()
'uniqueFloats temp()
'qSortFloats LBOUND(temp), UBOUND(temp), temp()
'reverseFloats temp()
'PRINT JoinFloats$(temp(), 0, 10, " ")
'a() must be initialized as redim a(lb to ub)
SUB uniqueFloats
(a
() AS _FLOAT) 'make all the items in the a array unique like a proper set t(lba) = a(lba): ti = lba
FOR i
= lba
+ 1 TO UBOUND(a
) 'for each element in array u = -1
FOR j
= lba
TO ti
'check if not already in new build IF u
THEN 'OK add it to rebuild ti = ti + 1
t(ti) = a(i)
FOR i
= lba
TO ti
'now copy the unique elements into array a(i) = t(i)
Hi = finish: Lo = start
Middle = a((Lo + Hi) / 2) 'find middle of array
Lo = Lo + 1: Hi = Hi - 1
IF Hi
> start
THEN qSortFloats start
, Hi
, a
() IF Lo
< finish
THEN qSortFloats Lo
, finish
, a
()
t(ti) = a(i)
ti = ti + 1
a(i) = t(i)
'notes: REDIM the a(0) as _float to be loaded before calling Split '<<<<<<<<<<<<<<<<<<<<<<< IMPORTANT!!!!
' I am hoping _floats will cover any number type
' bplus modifications of Galleon fix of Bulrush Split reply #13
' http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=1612.0
' this sub further developed and tested here: \test\Strings\Split test.bas
copy = mystr 'make copy since we are messing with mystr
'special case if delim is space, probably want to remove all excess space
copy
= MID$(copy
, 1, p
- 1) + MID$(copy
, p
+ 1) curpos = 1
arrpos = 0
dpos
= INSTR(curpos
, copy
, delim
) a
(arrpos
) = VAL(MID$(copy
, curpos
, dpos
- curpos
)) arrpos = arrpos + 1
curpos
= dpos
+ LEN(delim
) dpos
= INSTR(curpos
, copy
, delim
) a
(arrpos
) = VAL(MID$(copy
, curpos
))
JoinFloats$ = b