Computer Science Canada Alphabetize a List |
Author: | Beastinonyou [ Sun Nov 13, 2011 2:54 pm ] |
Post subject: | Alphabetize a List |
The other day, My mother was looking over my marks for my programming course, and she told me, "you should try and make a program that can alphabetize our movie lists for me", because she manually types them all up, in text files. Considering how easy it is to open and read/write to text files, It'd be a cool thing for her to use, not knowing a clue about what programming is/can do. Generally speaking, what could be the process in which you would organize a list to be alphabetical? I would store all the titles in an array, and then alphabetize them into a different array, then write the new array into a different text file. How should I go about: 1. If I have 26 words, a different letter of the alphabet that starts each word, and I have a new word that starts with 'K', how would I place that word where it should be in the array, and shift the rest of the words 2. If I have multiple words starting with a Letter, how would I go about continuing to more letters. I'll start working out these myself, as it's a lot easier to have help when you get stuck, rather than getting stuck, then posting and waiting for help. |
Author: | Aange10 [ Sun Nov 13, 2011 3:04 pm ] | ||
Post subject: | RE:Alphabetize a List | ||
Hmm, I too have done this. I figured the first part out pretty easy, but I didnt do the 2nd part. Though I'm sure recursion would be the solution. But anyways heres the source code I made a while back.
|
Author: | Tony [ Sun Nov 13, 2011 3:25 pm ] |
Post subject: | RE:Alphabetize a List |
why not just sort the array? |
Author: | Beastinonyou [ Sun Nov 13, 2011 3:48 pm ] |
Post subject: | Re: Alphabetize a List |
Tony wrote: why not just sort the array? Well, that is essentially what I need to do. In order to sort them into the correct order, you would need to solve for my 2 questions above, wouldn't you? |
Author: | Tony [ Sun Nov 13, 2011 4:09 pm ] | ||
Post subject: | RE:Alphabetize a List | ||
if I'm reading this correctly, then 1) how would one sort: 1, 2, 3, 2 2) how would one sort: 10, 11, 12 I'm assuming that you want words to be in http://en.wikipedia.org/wiki/Lexicographical_order so any off-the-shelf sorting algorithm of your choice would work.
|