It's better than some, but you'd really want to do a selection or insertion sort to add your new elements, I think, depending on your data structure.
The problem is that bubble sort only ever moves an element 1 spot. So if you add an element that would normally go into position 1 of a 1000-item list at the end of the pre-sorted list, you're looking at 1000 iterations over the whole list to "bump" it up into position 1. Ouch...
--
Mike
In reply to Re: Re: Re: bubble sort in perl
by RMGir
in thread bubble sort in perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |