On Fri, Dec 16, 2011 at 14:00, jake kaiden <jakekaiden / yahoo.com> wrote:

> you could insert each entry from the startarray
> into the sortarray at the index that is the entry's length.

I haven't been reading this thread closely, so forgive me if my
assumption is wrong, but... assuming you're trying to sort by length,
that won't work.  Imagine if you have two 4-char strings inserted.
You'll have them at indices 4 and 5.  Then you get a 5-char string, so
you insert it at 5.  It will push the first 4-char string up by one.
(That's the one at 5, having been already pushed up once by the
second.).  So, the 5-char one will be sandwiched between two 4-char
ones, not sorted.

You could make it OK by checking for this, and increasing the index
until either the slot is empty or what's already there is longer.
This would be essentially an insertion sort, with a shortcut of
starting where it would be if the lengths were unique.

-Dave

-- 
LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence).
Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)