------art_60330_32057623.1151398606900
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 6/27/06, Dark Ambient <sambient / gmail.com> wrote:
>
> I finally have had more success, at least for the first part of the
> exercise. Thanks for all the help. I do have another question (will
> they ever stop) - in my code below as in Matthew's example the
> array.push doesn't take place till after the loop is exited.  Why is
> that, can't they be added incrementally ?  I did the array.push in the
> loop and it completely skipped over it, or seemed to at least.
>
>
> def sort words
>
>   u_words = []
>   s_words = []
>
>   continue = true
>   while continue
>   puts words
>   userword = gets.chomp.downcase
>   u_words.push(userword)
>   puts 'we now have these words in our list '
>   puts u_words
>   puts 'shall we continue?'
>   a = gets.chomp.downcase
>     if a == 'yes'
>       continue = true
>             else
>               continue = false
>             end
>             puts 'we now have these words in our list '
>   puts u_words
>     end
> end
>   sort 'Please enter a word for sorting'


# Always try to keep your code simple
loop {
    puts words
    userword = gets.chomp.downcase
    break if userword == "stop"
    u_words << userwords
}
# I understand that you have to implement your sorting algorithm yourself,
that is
# a very good exercise.
mysort( u_words )
^^^^^^^  yes, you are going to write this!

Here is how to go for it
http://en.wikipedia.org/wiki/Sorting_algorithms

use bubble sort or insertion sort (the later is much better).
Stay away from the sophisticated algorithms for now.

Never forget what the ancient Greeks said:
    Learning is Suffering.

Hang in there

Robert

> I have a ways to go to complete this little tiny project but I must
> not use array.sort.
>
> Stuart
>
> On 6/26/06, Matthew Smillie <M.B.Smillie / sms.ed.ac.uk> wrote:
> > On Jun 26, 2006, at 20:24, Dark Ambient wrote:
>
> > def sortwords
> >    words = []
> >    continue = false
> >    while continue
> >      word = gets.chomp.downcase
> >      if word == 'stop'
> >        continue = false
> >      elsif word == 'hello'
> >        # or some other special case.
> >        puts "hello yourself"
> >      else
> >        # default behaviour
> >        words.push(word)
> >      end
> >    end
> >    return words.sort
> > end
> >
> > sortwords # (input 'foo', 'bar', 'baz', 'stop')
> > => ["bar", "baz", "foo"]
> >
> >
> > matthew smillie.
> >
> >
>
>


-- 
Deux choses sont infinies : l'univers et la bóŐise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

------art_60330_32057623.1151398606900--