🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.acorn.programmer
Article #18

Re: Sorting algorithms

#18
From: Jean-Michel
Date: Wed, 11 Nov 2026 19:36
106 lines
4346 bytes
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
Technical Details
Message-ID: <bdd535365d.jmb@jmc.bruck.orange.fr>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <5d336712aebob@sick-of-spam.invalid> <5d3622ac84Paul@sprie.nl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Jean-Michel <jmc.bruck@orange.fr>
Newsgroups: comp.sys.acorn.programmer
Subject: Re: Sorting algorithms
Date: Wed, 11 Nov 2026 20:36:03 +0100
Organization: Jean-Michel
Lines: 106
Message-ID: <bdd535365d.jmb@jmc.bruck.orange.fr>
References: <5d336712aebob@sick-of-spam.invalid> <5d3622ac84Paul@sprie.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 11 Nov 2026 19:36:19 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3514132"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19tNqfqiBG2MwtlSxVqvDn5kp8MkJkct18="; posting-host="fd838a23ccd45cb03770a62949a169d8"
User-Agent: Messenger-Pro/9.03 (MsgServe/9.03) (RISC-OS/5.31) NewsHound/v1.53-32 RC1
Cancel-Lock: sha1:Ta8k1gY4jBSzvgQqI+4iJdx1bBA= sha256:KWcDNa7wem9ZA2+8apFUiq8UM+c9EId7yxP1lOW/OjY=
	sha1:Izj3XJxiV3K/gXwuRJjkkxIpQRw= sha256:NmaI4x7XjJY8ABbUwcqTHQOhGMbbw1RRHSaWGLyul9Y=
X-Editor: EmailEdit 2.04