A basic string sorting routine would just sort based on ASCII
codepoints (see a list at
http://urltea.com/2tu7 ).
So you could do this in Ruby 1.9:
irb(main):002:0> class String
irb(main):003:1> def <=> other
irb(main):004:2> self.each_char.map(&
rd) <=> other.each_char.map(&
rd)
irb(main):005:2> end
irb(main):006:1> end
<, >, ==, !=, etc. are all defined in terms of <=>, the spaceship
operator, so all of the previous operations are affected when we
define <=>. Arrays sort by comparing the first non-matching element.
irb(main):011:0> %w[a c b g h j g p q].sort
=> ["a", "b", "c", "g", "g", "h", "j", "p", "q"]
Of course this has a lot of deficiencies:
irb(main):014:0> %w[a c b g h j g p q Z A G].sort
=> ["A", "G", "Z", "a", "b", "c", "g", "g", "h", "j", "p", "q"]
So we could downcase each character or something.
But even advanced sorting algorithms have problems -- German sorts
beta as nn or something and lots of other languages have similar
issues. Book listings generally don't include words like "the" when
sorting, etc. I would decide those before starting.