Author |
Message |
sensfan
|
Posted: 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...) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: 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') |
|
|
|
|
![](images/spacer.gif) |
codemage
![](http://usera.imagecave.com/codemage/codemage-small.gif)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Nov 07, 2005 1:01 pm Post subject: (No subject) |
|
|
jamonathin - capital letters actually have a lower value.
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. |
|
|
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Mon Nov 07, 2005 2:21 pm Post subject: (No subject) |
|
|
Tony wrote: jamonathin - capital letters actually have a lower value.
output wrote:
false
Whoops@! lol . . .. maybe i should check next time
never knew about that boolean check, meh, learn somethin every day . . |
|
|
|
|
![](images/spacer.gif) |
MysticVegeta
![](http://www.geocities.com/ohsoinsane/my_avatar.JPG)
|
Posted: Mon Nov 07, 2005 2:42 pm Post subject: (No subject) |
|
|
"A" = 65
"a" = 97
65 < 97 |
|
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: 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() |
|
|
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Flikerator
|
Posted: 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 Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
beard0
![](http://ugray.be/compsci/silly.gif)
|
Posted: 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 Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
|