所以我对 QB64 并不太熟悉,而且文档很少,所以我遇到了麻烦。
TYPE character
FName AS STRING * 12
LName AS STRING * 12
ID_Num AS INTEGER
Year AS STRING * 2
GPA AS DOUBLE
END TYPE
DIM LENGTH AS INTEGER
LENGTH = 11
REDIM chars(0) AS character
CLS
n$ = "names1.txt"
OPEN n$ FOR INPUT AS #1
k = -1
WHILE (NOT (EOF(1)))
k = k + 1
REDIM _PRESERVE chars(k) AS character
INPUT #1, chars(k).FName, chars(k).LName, chars(k).ID_Num, chars(k).Year,
chars(k).GPA
WEND
CLOSE #1
CALL sortArray(chars(), LENGTH)
SUB sortArray (score() AS INTEGER, SIZE AS INTEGER)
DIM x AS INTEGER
DIM y AS INTEGER
DIM COMPS AS INTEGER
x = 0
y = 0
COMPS = SIZE - 1
WHILE y < COMPS
x = 0
WHILE x < COMPS
IF score(x) > score(x + 1) THEN
CALL swap2(score(), x)
END IF
x = x + 1
WEND
y = y + 1
WEND
END SUB
SUB swap2 (score() AS INTEGER, x AS INTEGER)
DIM temp AS INTEGER
temp = score(x + 1)
score(x + 1) = score(x)
score(x) = temp
END SUB
我在以下行收到错误 - “传递给子的数组类型不正确”:
CALL sortArray(chars(), LENGTH)
我假设因为我在上面使用了 REDIM,所以 sub 没有正确处理它,但我不确定如何解决这个问题。最终,我试图将文件读入数组,对该数组进行排序,然后将其打印给用户。目前,我对如何对数组进行实际排序感到困惑。
任何帮助将不胜感激。谢谢!