Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #6733

Re: Sorting algorithms

From Jean-Michel <jmc.bruck@orange.fr>
Newsgroups comp.sys.acorn.programmer
Subject Re: Sorting algorithms
Date 2026-11-11 20:36 +0100
Organization Jean-Michel
Message-ID <bdd535365d.jmb@jmc.bruck.orange.fr> (permalink)
References <5d336712aebob@sick-of-spam.invalid> <5d3622ac84Paul@sprie.nl>

Show all headers | View raw


In message <5d3622ac84Paul@sprie.nl>
          Paul Sprangers <Paul@sprie.nl> wrote:

> I've written a short BASIC program that sorts the lines in a text file,
> taking capitals, undercasts and all sorts of diacritics, as well most other
> characters into account.

> My own example has nearly 6000 lines.
> The BASIC version took about 23 seconds to sort them, while the compiled
> version took less than 3 seconds to do the job. (On a 4té2 computer.)

> The text file is not included, but you should rename yours to "Texts" in
> order to let the program do its work. If your text file counts more than
> 6000 lines, you should change the DIM's in the program. Compile the program
> with the freely available !ABC compiler. Remember that the compiled version
> needs quite a big NEXT slot.

> There are much better or memory friendly ways to do this, but as an example
> it may have some use.

> Paul



> REM DIM two string arrays,
> REM big enough to store your lines.
> REM My example had 5913 lines.

> DIM text$(5913), dummy$(5913)

> REM Now store every line into both arrays.
> REM The dummy array will be adjusted on the fly,
> REM by changing undercast into capitals and by
> REM removing diacritics, in FNcase (see botom).

> f%=OPENIN("Texts")
> IF f%>0 THEN
>   a%=0
>   REPEAT
>     a%+=1
>     text$(a%) = GET$#f%
>     dummy$(a%) = FNcase(text$(a%))
>   UNTIL EOF#f%
> ENDIF
> IF f%>0 THEN CLOSE#f%

> REM NOW the actual sorting will start

> OK% = TRUE
> time = TIME

> PROCsort

> t = TIME - time : REM The time needed in centiseconds.

> REM Finally, print the sorted lines

> FOR i% = 1 TO a% : PRINT STR$(i%) +": " + text$(i%) : NEXT
> PRINT t
> END


> DEF PROCsort
> FOR i% = 1 TO a%
>   IF dummy$(i%) < dummy$(i%-1) THEN
>     SWAP text$(i%),text$(i%-1)
>     SWAP dummy$(i%),dummy$(i%-1)
>     OK% = FALSE
>   ENDIF
> NEXT
> IF NOT OK% THEN OK% = TRUE : PROCsort
> ENDPROC


> DEF FNcase(x$)
> y$=""
>   FOR j%= 1 TO LEN x$
>     c%=ASC(MID$(x$,j%,1))
>     IF c%>96 AND c%<123  THEN y$ += CHR$(c%-32) : REM undercast -> capital
>     IF c%>47 AND c%< 58  THEN y$ += CHR$(c%)    : REM numbers don't change
>     IF c%>64 AND c%< 91  THEN y$ += CHR$(c%)    : REM capitals don't change
>     IF c%>223 AND c%<230 THEN y$ += "A"         : REM diacritics removed
>     IF c%>231 AND c%<231 THEN y$ += "E"
>     IF c%>235 AND c%<240 THEN y$ += "I"
>     IF c%>241 AND c%<247 THEN y$ += "O"
>     IF c%>248 AND c%<253 THEN y$ += "U"
>     IF c%=229 OR c%=197  THEN y$ += "A"
>     IF c%=230 OR c%=198  THEN y$ += "AE"
>     IF c%=231 OR c%=199  THEN y$ += "C"
>     IF c%=241 OR c%=209  THEN y$ += "N"
>     IF c%=248 OR c%=216  THEN y$ += "O"
>     IF c%=223            THEN y$ += "SS"
>     IF c%=255            THEN y$ += "Y"
>   NEXT
> =y$

Interesting, good ASCII table usage.
Just a little error, for E "diacritics", sorry I am French, we have many.

 IF c%>231 AND c%<231 THEN y$ += "E"
  => IF c%>231 AND c%<236 THEN y$ += "E"

I am waiting the same for UTF8...

-- 
Jean-Michel

Back to comp.sys.acorn.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Sorting algorithms Bob Latham <bob@sick-of-spam.invalid> - 2026-11-06 08:45 +0000
  Re: Sorting algorithms Jean-Michel <jmc.bruck@orange.fr> - 2026-11-06 17:30 +0100
    Re: Sorting algorithms Bob Latham <bob@sick-of-spam.invalid> - 2026-11-06 17:57 +0000
      Re: Sorting algorithms Jean-Michel <jmc.bruck@orange.fr> - 2026-11-06 20:28 +0100
  Re: Sorting algorithms Paul Sprangers <Paul@sprie.nl> - 2026-11-07 13:36 +0100
    Re: Sorting algorithms Jean-Michel <jmc.bruck@orange.fr> - 2026-11-07 18:55 +0100
      Re: Sorting algorithms Paul Sprangers <Paul@sprie.nl> - 2026-11-07 19:41 +0100
        Re: Sorting algorithms Martin <News04@avisoft.f9.co.uk> - 2026-11-07 19:48 +0000
          Re: Sorting algorithms Bob Latham <bob@sick-of-spam.invalid> - 2026-11-08 12:13 +0000
  Re: Sorting algorithms Paul Sprangers <Paul@sprie.nl> - 2026-11-11 17:06 +0100
    Re: Sorting algorithms Martin <News04@avisoft.f9.co.uk> - 2026-11-11 17:14 +0000
      Re: Sorting algorithms Paul Sprangers <Paul@sprie.nl> - 2026-11-11 19:25 +0100
        Re: Sorting algorithms Sebastian Barthel <naitsabes@freenet.de> - 2026-11-16 18:31 +0000
          Re: Sorting algorithms Paul Sprangers <Paul@sprie.nl> - 2026-11-16 20:15 +0100
            Re: Sorting algorithms Bob Latham <bob@sick-of-spam.invalid> - 2026-11-17 09:11 +0000
          Re: Sorting algorithms Martin <News04@avisoft.f9.co.uk> - 2026-11-16 19:17 +0000
    Re: Sorting algorithms Jean-Michel <jmc.bruck@orange.fr> - 2026-11-11 20:36 +0100
      Re: Sorting algorithms Paul Sprangers <Paul@sprie.nl> - 2026-11-11 22:55 +0100

csiph-web