Commodore 64 (C64) Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Alphabetizing and BASIC

 
Post new topic   Reply to topic    Commodore 64 (C64) Forum Index -> Scene
View previous topic :: View next topic  
Author Message
mistermsk
Grandmaster of C64
Grandmaster of C64


Joined: 29 Jun 2009
Age: 40
Posts: 2618
Location: Baltimore, MD Favorite Games: Ultima ][, Wasteland

PostPosted: Wed Sep 21, 2011 6:09 pm    Post subject: Alphabetizing and BASIC Reply with quote

Hi All,


I got an array in BASIC. Is there a fast way to alphabetize it?
_________________
Back to top
View user's profile Send private message Visit poster's website
iAN CooG
Master of C64
Master of C64


Joined: 31 Jan 2003
Age: 42
Posts: 1153
Location: Italy

PostPosted: Wed Sep 21, 2011 6:32 pm    Post subject: Reply with quote

http://en.wikipedia.org/wiki/Bubble_sort
http://en.wikipedia.org/wiki/Quicksort

bubblesort is easier to implement.
_________________
-=[]=--- iAN CooG/HVSC & C64Intros ---=[]=-
Back to top
View user's profile Send private message Send e-mail Visit poster's website
groepaz
Immortal Grandmaster of C64
Immortal Grandmaster of C64


Joined: 13 Oct 2004
Posts: 4702

PostPosted: Wed Sep 21, 2011 6:41 pm    Post subject: Reply with quote

i would recommend http://de.wikipedia.org/wiki/Shellsort as a general purpose algo on the c64... it is a bit slower than quicksort, but is easier to implement and needs much less memory during sorting (no recursion.
_________________
Back to top
View user's profile Send private message
SkydivinGirl
C64 Enthusiast
C64 Enthusiast


Joined: 18 Aug 2009
Age: 39
Posts: 631
Location: Raleigh, NC USA

PostPosted: Wed Sep 21, 2011 7:01 pm    Post subject: Reply with quote

I usually did a bubble sort for my C64 basic programs but the options others have mentioned are all good choices. Smile

Heather
Back to top
View user's profile Send private message
groepaz
Immortal Grandmaster of C64
Immortal Grandmaster of C64


Joined: 13 Oct 2004
Posts: 4702

PostPosted: Wed Sep 21, 2011 8:17 pm    Post subject: Reply with quote

btw as for selecting an algo: rule of thumb is that for 16 elements or less, bubble sort can be sufficient (and equally fast as others). for more, better use shellsort or quicksort.
_________________
Back to top
View user's profile Send private message
mistermsk
Grandmaster of C64
Grandmaster of C64


Joined: 29 Jun 2009
Age: 40
Posts: 2618
Location: Baltimore, MD Favorite Games: Ultima ][, Wasteland

PostPosted: Wed Sep 21, 2011 8:46 pm    Post subject: Reply with quote

Thanks a lot guys (and gals). Smile

I guess bubble it is then. Noted the point about big arrays Goepaz.

I also found this site about VBSCRIPT sorting here.

Riccardo Quintan from stackoverflow.com wrote:
for a = UBound(ArrayOfTerms) - 1 To 0 Step -1
for j= 0 to a
if ArrayOfTerms(j)>ArrayOfTerms(j+1) then
temp=ArrayOfTerms(j+1)
ArrayOfTerms(j+1)=ArrayOfTerms(j)
ArrayOfTerms(j)=temp
end if
next
next


So I said. Lets write it in Commodore BASIC.

Code:
10 rem load array with unsorted text
20 upper=6:rem upper boundery
30 dim b$(upper)
40 b$(0)="how"
50 b$(1)="hello"
60 b$(2)="are"
70 b$(3)="you"
80 b$(4)="test"
90 b$(5)="not bad"
100 rem sort array
110 for a=upper-1 to 0 step-1:forj=0toa
120 z$=b$(j):x$=b$(j+1)
130 ifz$>x$thenb$(j+1)=z$:b$(j)=x$
140 next:next
200 rem print sorted array
210 fora=0to5 step+1
220 printb$(a)
230 next


LOL. Very Happy It works.
_________________
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Commodore 64 (C64) Forum Index -> Scene All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Tip: Get C64 Forever for super-comfy C64 emulation with pre-installed games, demos and other goodies!


Powered by phpBB © 2001, 2005 phpBB Group