Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.acorn.programmer > #6730
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Paul Sprangers <Paul@sprie.nl> |
| Newsgroups | comp.sys.acorn.programmer |
| Subject | Re: Sorting algorithms |
| Date | Wed, 11 Nov 2026 17:06:45 +0100 (Custom) |
| Organization | None |
| Lines | 95 |
| Message-ID | <5d3622ac84Paul@sprie.nl> (permalink) |
| References | <5d336712aebob@sick-of-spam.invalid> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-1 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Wed, 11 Nov 2026 16:06:54 +0000 (UTC) |
| Injection-Info | dont-email.me; logging-data="3345171"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HnL5cvfB6EJsFQE5xZw7q9+Wxrw9W3mk="; posting-host="e144510d219e3c252735c723c065e6c7" |
| User-Agent | Pluto/3.20 (RISC OS/5.31) NewsHound/v1.54 |
| Cancel-Lock | sha1:Ar/2/XnFOEe2PCuUVPdsAVC6vKw= sha256:md5vLUf99tk//OBvejs0ZXsmbUbEOuu0lxrYKgl41I8= sha1:Saa9N5bkeeOjJjm/5JFW2wD48rE= sha256:HyDSRn1zkYKbNEceCXptu4PNm/5KUUYNk9eMaOd7Tcw= |
| Xref | csiph.com comp.sys.acorn.programmer:6730 |
Show key headers only | View raw
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$
--
https://riscos.sprie.nl
Back to comp.sys.acorn.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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