1) Thank you very much everyone!
2) LOL, I've been working erroneously well all my life!
I modified the program a bit.
(I hope I did not have more errors)
Code: Select all
'lrcvs 01.10.17
'program to eliminate repeated elements in an array.
'1) we sort the initial array, using quicksort.
'2) we remove the repeated elements, skipping the ones that are the same
'and reducing the time of "cleaning the repeated elements".
DECLARE SUB ordenar2 (s()AS INTEGER,inicio AS INTEGER,final AS INTEGER)
DIM AS INTEGER c,f,n,x
CLS
x = 30000000 'x = number of array elements
DIM s (x)AS INTEGER 'this is the main array
DIM t (x)AS INTEGER 'this is the auxiliary array
RANDOMIZE, 3
FOR n = 1 TO x
s(n) = (INT(RND * x) + 1) 'here we write the values in the main array
'print s(n);" "; 'show elements of auxiliary array
NEXT n
PRINT
PRINT "init array of "; x; " elements, some repeated"
PRINT
ordenar2 (s(),1,x) 'sort the elements
'******************************************************************************
'remove elements repeted
f = 1 'f = counter for the main array
c = 1 'c = counter for the auxiliary array
t(c) = s(c)
WHILE f < x
IF s(f + 1) = t(c) THEN
f = f + 1
ELSE
c = c + 1
t(c) = s(f + 1)
END IF
WEND
'******************************************************************************
'show elements of auxiliary array
'for n = 1 to c-1
' print t(n);" ";
'next n
PRINT
PRINT "there are ";c;" unique elements"
PRINT
PRINT "end"
SLEEP
END
'******************************************************************************
SUB ordenar2 (s()AS INTEGER,inicio AS INTEGER,final AS INTEGER)
'quick sort
DIM AS INTEGER i,j,y
i = inicio
j = final
y = s(INT(i + j) / 2)
WHILE i < j
WHILE s(i) < y
i = i + 1
WEND
WHILE s(j) > y
j = j - 1
WEND
IF i <= j THEN
SWAP s(i), s(j)
i = i + 1
j = j - 1
END IF
WEND
IF j > inicio THEN ordenar2(s(),inicio,j)
IF i < final THEN ordenar2(s(),i,final)
END SUB