I think you're swapping unnecessarily. Consider this algorithm:
- start with item n where n = 10. if my insert item is less than that, exit
- if my insert item is bigger than item n, then set item n to my insert item, and quit
- reduce n by 1, copy item n to item n+1 and repeat from the previous step
See.. I don't see any swaps needed. Just a push-down.
Of course, if you find the location using a binary search, it might be faster,
and then use a splice to insert it, and you're now at the other algorithm. {grin}
-- Randal L. Schwartz, Perl hacker