Alphabetize a List
Author |
Message |
Beastinonyou
|
Posted: 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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Aange10
|
Posted: 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.
Turing: |
var max_a : int := 0
put "How many words do you have?"
get max_a
var a_alphabetize : array 1 .. max_a of string
var b_alphabetize : flexible array 1 .. 1 of string
cls
put "Please insert your words!"
for i : 1 .. upper(a_alphabetize )
put "Word (",i, "): " ..
get a_alphabetize (i ): *
end for
for e : 65 .. 91
for i : 1 .. upper (a_alphabetize )
if ord (a_alphabetize (i ) (1)) = e or ord (a_alphabetize (i ) (1)) = (e + 26) then % If character is (I.E: A)
b_alphabetize (upper (b_alphabetize )) := a_alphabetize (i ) % Take the string and put it to b
new b_alphabetize, upper (b_alphabetize ) + 1 % Expand b
end if
end for
end for
View.Set ("text")
for i : 1 .. upper(b_alphabetize ) - 1
put "B(",i, "):", b_alphabetize (i )
end for
|
|
|
|
|
|
|
Tony
|
|
|
|
|
Beastinonyou
|
Posted: 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? |
|
|
|
|
|
Tony
|
|
|
|
|
|
|