|
Post by B+ on May 2, 2021 16:33:02 GMT
' Illustrated Human Sort.txt for JB v1.01 2016-08-30 translated from ' Illustrated Human Sort.bas SmallBASIC 0.12.6 [B+=MGA] 2016-08-29
n = 25 sp8$ = " " dim fileThis$(n + 1)
call pa 0, -1, "File This:" call pa 30, -1, "Filed:"
'set up work pile for x = 1 TO n c$ = mid$("ABCDEFGHIJKLMNOPQRSTUVWXYZ", int(rnd(0) * 26) + 1, 1) r = int(rnd(0) * 7) for i = 0 to r c$ = c$ + mid$("abcdefghijklmnopqrstuvwxyz", int(rnd(0) * 26) + 1, 1) next if len(c$) < 5 then c$ = ":" + mid$("()<>{}[]/\|OoDP", int(rnd(0) * 15) + 1, 1) + " " + c$ fileThis$(x) = left$(c$ + sp8$, 8) call pa 0, x, fileThis$(x) next
'file it dim filed$(n + 1) for i = 1 to n call pa 15, i, fileThis$(i) call pa 0, i, sp8$ call d1 if i = 1 then filed$(1) = fileThis$(1) call pa 30, 1, fileThis$(1) call pa 15, 1, sp8$ call d1 else iPoint = findIndex(fileThis$(i), i - 1) 'insert filed, iPoint, fileThis(i) for j = i to iPoint + 1 step -1 filed$(j) = filed$(j - 1) call pa 30, j, filed$(j) next filed$(iPoint) = fileThis$(i) call pa 30, iPoint, sp8$ call d1 call pa 30, iPoint, filed$(iPoint) call pa 15, i, sp8$ end if next call pa 0, n + 2, " I am done sorting things out!"
function findIndex(find$, ub) lb = 1 call pa 28, ub, "?" call d1 if find$ >= filed$(ub) then findIndex = ub + 1 call pa 28, ub, " " call d1 exit function else high = ub call pa 28, ub, "<" call d1 end if call pa 28, lb, "?" call d1 if find$ <= filed$(lb) then findIndex = lb call pa 28, lb, " " call pa 28, high, " " call d1 exit function else low = lb call pa 28, lb, ">" call d1 end if midi = int((high - low) / 2) + low call pa 28, midi, "?" call d1 while midi <> low if find$ = filed$(midi) then findIndex = midi call pa 28, midi, " " call pa 28, high, " " call pa 28, low, " " call d1 exit function end if if find$ < filed$(midi) then call pa 28, high, " " high = midi call pa 28, midi, "<" call d1 else call pa 28, low, " " low = midi call pa 28, midi, ">" call d1 end if midi = int((high - low ) / 2) + low call pa 28, midi, "?" call d1 wend call pa 28, midi, " " call pa 28, high, " " call pa 28, low, " " call d1 findIndex = low + 1 end function
sub pa xCol, yRow, text$ locate xCol + 2, yRow + 2: print text$ end sub
sub d1 timer 1000, [timesup] wait [timesup] timer 0 end sub
|
|