Sorting arrays

Previous topic - Next topic

carlus90

Hello to everybody! I'm quite new to GLBasic (I use it since 2 months) and I'm very satisfied of it. I've never used an easier programming language getting such beautiful results!
Now, I have a question to ask you. Is there a way to sort arrays alphabetically?
Thanks for your help.

Kitty Hello

there's no built-in sort function so far. A simple bubble sort woulde be:

Code (glbasic) Select
FUNCTION sort: a$[]
LOCAL i, tmp$
   FOR i=0 TO LEN(a$[])-2
      IF a$[i] > a$[i+1]
         tmp$ = a$[i]
         a$[i]=a$[i+1]
         a$[i+1]=tmp$
         IF i>=0 THEN DEC i, 2
      ENDIF
   NEXT
ENDFUNCTION
(not tested)

carlus90

Thank you very much, I'll try it.