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

Username:   Password: 
 RegisterRegister   
 Alphabetize a List
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Beastinonyou




PostPosted: 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
Sponsor
sponsor
Aange10




PostPosted: 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




PostPosted: Sun Nov 13, 2011 3:25 pm   Post subject: RE:Alphabetize a List

why not just sort the array?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Beastinonyou




PostPosted: 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




PostPosted: 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.

Turing:

put "Herp" > "Derp"
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 5 Posts ]
Jump to:   


Style:  
Search: