Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Sort Words Alphabetically
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sensfan




PostPosted: Mon Nov 07, 2005 11:50 am   Post subject: Sort Words Alphabetically

Hey, I'm kind of new to this so I'm not quite sure what to do. How do you sort words alphabetically? I've got very little code written so far because I'm not sure what to use. I really don't know what else to say. Any help would be appreciated - especially if I can get it before 4th period.

--Thanks.

(Senators have the Cup this year...)
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Mon Nov 07, 2005 12:51 pm   Post subject: (No subject)

You should post what code you do have, no matter how bad it is, that way we can se what we're working with.

Each letter(character) has a number value. Look up ord and chr in Turing Reference (F10). What you can do from there is pick apart the word and see which value the letter(character) is. Then you can arrange from lowest number to highest.

*Note* Capital letters have higher values then lower case.
(i.e 'A' > 'a')
codemage




PostPosted: Mon Nov 07, 2005 1:01 pm   Post subject: (No subject)

Turing understands how to compare strings in the same way that it can compare numeric values. If you can figure out how to sort numeric values, you can do strings.

I may have to do a tutorial on "sorting in Turing" for y'all.

EDIT: You might be able to glean some help from here:
http://www.compsci.ca/v2/viewtopic.php?t=4091&highlight=bubble+selection
Tony




PostPosted: Mon Nov 07, 2005 1:01 pm   Post subject: (No subject)

jamonathin - capital letters actually have a lower value.
Turing:

put "A" > "a"

output wrote:

false


you could compare whole words as so
Turing:

put "Tony" > "Dan"

output wrote:

true


sensfan - so just loop through your list of words and compare if one comes before the other, then rearrange them if needed.
jamonathin




PostPosted: Mon Nov 07, 2005 2:21 pm   Post subject: (No subject)

Tony wrote:
jamonathin - capital letters actually have a lower value.
Turing:

put "A" > "a"

output wrote:

false

Whoops@! lol . . Drunk .. maybe i should check next time

never knew about that boolean check, meh, learn somethin every day . .
MysticVegeta




PostPosted: Mon Nov 07, 2005 2:42 pm   Post subject: (No subject)

"A" = 65
"a" = 97

65 < 97
[Gandalf]




PostPosted: Mon Nov 07, 2005 3:40 pm   Post subject: (No subject)

code:
put "zzz" > "aargh"
if "Zzz" > "aargh" then   
    put "This works flawlessly"
else
    put "Now you see the problem with this method"
end if

You must take into account upper/lower case letters while doing this too. A good way of solving it is by looking up Str.Upper() and/or Str.Lower()
jamonathin




PostPosted: Mon Nov 07, 2005 5:19 pm   Post subject: (No subject)

Mod edit: Now now, no need to be snide. We're all friends here, right?
Sponsor
Sponsor
Sponsor
sponsor
Flikerator




PostPosted: Tue Nov 08, 2005 9:40 am   Post subject: (No subject)

[Gandalf] wrote:
code:
put "zzz" > "aargh"
if "Zzz" > "aargh" then   
    put "This works flawlessly"
else
    put "Now you see the problem with this method"
end if

You must take into account upper/lower case letters while doing this too. A good way of solving it is by looking up Str.Upper() and/or Str.Lower()


Omg thanks, I was looking for that! I made my own functions to do it in some programs, now I can lesson the lines Razz
beard0




PostPosted: Tue Nov 08, 2005 10:11 am   Post subject: (No subject)

Flikerator wrote:
now I can lesson the lines


Here's a lesson for you: Now you can lessen the number of lines. Razz
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: