[EMAIL PROTECTED] wrote:

I'm having problems trying to figure out 'bubble sort'. I'm working on
assignment for a class and I have to do the following:

Use the following code as a starting point for the next lab.

#!/usr/bin/perl

@array = (5,3,2,1,4);

## include your code here ##

foreach $elem (@array){
  print "$elem";
}


Use two loops and an if statement to sort the contents of the array so
that the number go from lowest to highest. (This is actually a very
inefficient way to sort an array.)

HINT: One loop should progress through the array comparing and
swapping adjacent elements (if necessary). The second loop is used to
make sure this happens multiple times based on the size of the array.

I can't for the life of me get this to work. I either hit an infinite
loop or I get nothing.

Thoughts?

Show us what you've written and explain how you mean it to work. We will
be able to explain where you have made mistakes.

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to