Work inside out.  If the inner loop is working properly, then there
should be some difference after the initial pass and you won't be left
with nothing or infinity (unless that's the trouble loop, but the proper
inner loop is easy enough to see..).

[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?
>
>
>   


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


Reply via email to