Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.lang.basic.misc > #240
| From | Todd Vargo <tlvargo@sbcglobal.netz> |
|---|---|
| Newsgroups | comp.lang.basic.misc |
| Subject | Re: Sorting: 1 to 99 |
| Date | 2012-03-20 20:05 -0500 |
| Organization | albasani.net |
| Message-ID | <jkb60d$7t8$1@news.albasani.net> (permalink) |
| References | <2oM9r.4774$%E2.520@viwinnwfe01.internal.bigpond.com> <4f688d9e$0$6982$e4fe514c@news2.news.xs4all.nl> <ij5ar.4798$%E2.1615@viwinnwfe01.internal.bigpond.com> |
On 3/20/2012 2:58 PM, DonH wrote:
>
> # Most sorting methods rely on comparing the items with each other, in
> successive fashion.
> I wanted to get away from that, if I could.
> The Alphabet is another permanent (external) sequence which could be
> referenced, but may need conversion to/from ASCII codes to fit into the
> above program.
> A dimensioned array only operates with numerics, ie.a(n); also this does
> not allow for "repeats" (see above), which is not important if overwriting
> of the item is permitted.
> If you can streamline my ("persort"? = permanent external reference)
> program, feel free.
> Limiting either nested FOR loop to N can cause a problem.
> ============================================================
> "SWAP" is a QBasic utility, but how does it work? It seemingly compares
> numbers or characters according to ASCII code, but while this is thorough
> when all characters are alphabetic (eg. sorting list of names), it seems to
> stop after the numerics when, eg., 01H, 87P, 04W, 13E, 99Z, 11T, are used.
> Note: insertion of a leading zero is necessary for numbers less than 10, or
> they won't sort satisfactorily. All elements are defined as characters.
> ===============================================================
Check for duplicates and sort as array is being populated.
CLS
DIM a(99) AS STRING
PRINT "== Read data =="
FOR i = 1 TO 99
ON ERROR GOTO Handler:
READ a(i)
IF abort THEN EXIT FOR
ON ERROR GOTO 0
PRINT a(i)
dup = 0
FOR j = i - 1 TO 1 STEP -1 'check for dups
IF a(i) = a(j) THEN
dup = 1
EXIT FOR
END IF
NEXT j
IF dup = 0 THEN 'sort list
FOR j = i TO 1 STEP -1
IF a(j) < a(j - 1) THEN
SWAP a(j), a(j - 1)
ELSE
EXIT FOR
END IF
NEXT j
count = i
ELSE
i = i - 1
END IF
NEXT
LOCATE 1, 20
PRINT "== Sorted (with dups removed) =="
FOR i = 1 TO count
LOCATE i + 1, 20
PRINT a(i)
NEXT
DATA mouse, dog, 87P, 11T, cat, fish
DATA 99Z, 01H, 87P, 04W, 13E, cat
Handler:
abort = 1
RESUME NEXT
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Back to comp.lang.basic.misc | Previous | Next — Previous in thread | Next in thread | Find similar
Sorting: 1 to 99 "DonH" <donlhumphries@bigpond.com> - 2012-03-20 07:09 +1100
Re: Sorting: 1 to 99 who where <noone@home.net> - 2012-03-20 07:25 +0800
Re: Sorting: 1 to 99 "R.Wieser" <address@not.available> - 2012-03-20 15:08 +0100
Re: Sorting: 1 to 99 "DonH" <donlhumphries@bigpond.com> - 2012-03-21 06:58 +1100
Re: Sorting: 1 to 99 Todd Vargo <tlvargo@sbcglobal.netz> - 2012-03-20 20:05 -0500
Re: Sorting: 1 to 99 "R.Wieser" <address@not.available> - 2012-03-21 22:51 +0100
Re: Sorting: 1 to 99 Todd Vargo <tlvargo@sbcglobal.netz> - 2012-03-22 23:57 -0400
Re: Sorting: 1 to 99 - a possible non-sorting sorting solution "R.Wieser" <address@not.available> - 2012-03-23 10:21 +0100
Re: Sorting: 1 to 99 Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-03-21 09:28 +0200
csiph-web