59 lines
1.2 KiB
Plaintext
59 lines
1.2 KiB
Plaintext
a$ = "1 3 6 6 6 6 7 7 12 12 17"
|
|
b$ = "1 2 4 4 1"
|
|
|
|
print "Modes for ";a$
|
|
print modes$(a$)
|
|
print "Modes for ";b$
|
|
print modes$(b$)
|
|
|
|
function modes$(a$)
|
|
'get array size
|
|
n=0
|
|
t$ = "*"
|
|
while t$<>""
|
|
n=n+1
|
|
t$=word$(a$, n)
|
|
'print n, t$
|
|
wend
|
|
n=n-1
|
|
'print "n=", n
|
|
'dim array
|
|
'read in array
|
|
redim a(n)
|
|
for i = 1 to n
|
|
a(i)=val(word$(a$, i))
|
|
'print i, a(i)
|
|
next
|
|
'sort
|
|
sort a(), 1, n
|
|
'get the modes
|
|
occurence = 1
|
|
maxOccurence = 0
|
|
oldVal = a(1)
|
|
modes$ = ""
|
|
for i = 2 to n
|
|
'print i, a(i)
|
|
if a(i) = oldVal then
|
|
occurence = occurence + 1
|
|
else
|
|
select case
|
|
case occurence > maxOccurence
|
|
maxOccurence = occurence
|
|
modes$ = oldVal; " "
|
|
case occurence = maxOccurence
|
|
modes$ = modes$; oldVal; " "
|
|
end select
|
|
occurence = 1
|
|
end if
|
|
oldVal = a(i)
|
|
next
|
|
'check after loop
|
|
select case
|
|
case occurence > maxOccurence
|
|
maxOccurence = occurence
|
|
modes$ = oldVal; " "
|
|
case occurence = maxOccurence
|
|
modes$ = modes$; oldVal; " "
|
|
end select
|
|
end function
|