On 10/9/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I'm having problems trying to figure out 'bubble sort'. I'm working on > assignment for a class
Well, that *is* the only valid reason to code bubble sort in Perl, I must admit. I hope you're in a class about sorting algorithms, because this would be a poor exercise to use in a class on Perl. > I can't for the life of me get this to work. I either hit an infinite > loop or I get nothing. What have you tried so far? Can you show us your code, so we might be able to show you where you've gone wrong? The general idea of a bubble sort is that each pass through the array makes one element "bubble to the top". On the first pass, the highest element is moved to the end of the array. (Remember that each pass will compare items two at a time. When the highest element is encountered, your code will see that it's higher than the following element, so it will switch those two elements' positions. The highest element will then be in position to be compared with the next one, so it keeps "bubbling" down the line.) On each subsequent pass, another element is moved into position. If you have N objects, this means that N passes through the array will suffice to sort them. But you can improve the efficiency of this (by about 50%) if you give it some thought. Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/