in the sub there's the same thing ; string array and a number varible.
Here's the code:
Code: Select all
DECLARE SUB bubble (data$(), num!)
DECLARE SUB sort (data$(), num!)
DECLARE SUB shll (data$(), num!)
DECLARE SUB display (data$(), num!)
DECLARE SUB enterDATA (data$(), num!)
CLS
DIM data$(1 TO 1000)
DO
CALL enterDATA(data$(), num)
CALL sort(data$(), num)
PRINT
CALL display(data$(), num)
PRINT
INPUT "do you want to sort any more data [y/n]: ", yn$
PRINT
LOOP UNTIL yn$ = "n" OR yn$ = "N"
END
SUB bubble (data$(), num)
FOR index = 1 TO num - 1
FOR n = 1 TO num - index
IF data$(n) > data$(n + 1) THEN
SWAP data$(n), data$(n + 1)
END IF
NEXT n
NEXT index
END SUB
SUB display (data$(), num)
FOR i = 1 TO num
PRINT i; "."; data$(i)
NEXT i
END SUB
SUB enterDATA (data$(), num)
LET num = 0
DO
LET num = num + 1
INPUT "enter the data :", data$(num)
INPUT "do you want to enter any more data? [y/n] :", yn$
LOOP UNTIL yn$ = "n" OR yn$ = "N"
END SUB
SUB shll (data$(), num)
LET gap = INT(num / 2)
DO WHILE gap >= 1
DO
LET doneFLAG = 1
FOR index = 1 TO num - gap
IF data$(index) > data$(index + gap) THEN
SWAP data$(index), data$(index + gap)
LET doneFLAG = 0
END IF
NEXT index
LOOP UNTIL doneFLAG = 1
LET gap = INT(gap / 2)
LOOP
END SUB
SUB sort (data$(), num)
IF num < 30 THEN
CALL bubble(data$(), num)
ELSE
CALL shll(data$(), num)
END IF
END SUB