06-24-2024, 06:03 AM
To answer your question -- You simply don't have enough data for it to register for how long it takes to sort. 104 elements are sorted in 0.0000000000000000000001 seconds, or so, and your variable type only holds 0.000000001 seconds, or so. It's done before the timer clicks, so 0 zeros is the correct answer.
Increase the data pool and you'll see the time increase.
Increase the data pool and you'll see the time increase.
Code: (Select All)
DEFDBL T
RANDOMIZE TIMER
MakeList:
PRINT TAB(30); "Create 104 Unsorted elements (301 sets A to Z)"
DIM EL$(301 * 26)
FOR a = 1 TO 26
FOR b = 0 TO 300
EL$(a + b * 26) = CHR$(INT(RND * 26) + 65)
PRINT EL$(a + b * 26); " ";
NEXT
NEXT
T1 = TIMER ' start time
PRINT: PRINT "Start time is"; T1
BubbleSort:
pass = pass + 1
FOR a = 1 TO UBOUND(EL$) - 1 ' for first element to last-1 element of Orig$() array
' _Limit 30
'_limit 300
'_limit 3000
' _Limit 30000
IF EL$(a) > EL$(a + 1) THEN ' if this element is greater than next element, swap them,
SWAP EL$(a), EL$(a + 1)
swop = 1 ' and flag that a swap was made in this pass
END IF
NEXT
IF swop = 1 THEN swop = 0: GOTO BubbleSort '
T2 = TIMER ' finish time
PRINT: PRINT "Finish time is"; T2
FOR a = 1 TO 104: PRINT EL$(a); " ";: NEXT
PRINT: PRINT: PRINT "T1 is"; T1, "T2 is"; T2
PRINT: PRINT TAB(10); "Sorted in "; T2 - T1; "seconds, with "; pass; "passes"