Re: Bubble sort...

2007-10-15 Thread Chas. Owens
On 10/15/07, Dr.Ruud <[EMAIL PROTECTED]> wrote: snip > > or the old chestnut: > > > > $array[0] ^= $array[1] > > $array[1] ^= $array[0] > > $array[0] ^= $array[1] > > > > Which even works on strings (but not references) in Perl. > > With strings not without length-issues: snip Thats what I get for

Re: Bubble sort...

2007-10-15 Thread Dr.Ruud
"Chas. Owens" schreef: > Dr.Ruud: >> Jeff Pang: >>> my $tmp = $array[$_]; >>> $array[$_] = $array[$_+1]; >>> $array[$_+1] = $tmp; >> >> Alternative without a $tmp: >> >> @array[$_, $_+1] = @array[$_+1, $_]; >> >> (but actually it has 2 $tmp's) > > or the old c

Re: Bubble sort...

2007-10-15 Thread Chas. Owens
On 10/13/07, Dr.Ruud <[EMAIL PROTECTED]> wrote: > "Jeff Pang" schreef: > > > my $tmp = $array[$_]; > > $array[$_] = $array[$_+1]; > > $array[$_+1] = $tmp; > > Alternative without a $tmp: > > @array[$_, $_+1] = @array[$_+1, $_]; > > (but actually it has 2 $tmp's) sn

Re: Bubble sort...

2007-10-13 Thread Dr.Ruud
"Jeff Pang" schreef: > my $tmp = $array[$_]; > $array[$_] = $array[$_+1]; > $array[$_+1] = $tmp; Alternative without a $tmp: @array[$_, $_+1] = @array[$_+1, $_]; (but actually it has 2 $tmp's) -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-m

Re: Bubble sort...

2007-10-13 Thread [EMAIL PROTECTED]
On Oct 10, 1:51 pm, [EMAIL PROTECTED] (Tom Phoenix) wrote: > 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 > mu

Re: Bubble sort...

2007-10-13 Thread Jeff Pang
2007/10/12, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > > Here is what I had so far. I'm not sure exactly what I'm doing wrong. > > !/usr/bin/perl > > @array = (5,3,2,1,4); > @tmp_array; > > $i = 0; > while($i <= 5){ >if ($array[$i] > $array[$i+1]); > } >while ($i > 2) { >print "$tmp_arra

Re: Bubble sort...

2007-10-13 Thread [EMAIL PROTECTED]
On Oct 10, 1:57 pm, [EMAIL PROTECTED] (Rob Dixon) wrote: > [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

Re: Bubble sort...

2007-10-11 Thread usenet
On Oct 9, 6:06 pm, [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote: > I'm having problems trying to figure out 'bubble sort'. http://en.wikipedia.org/wiki/Bubble_sort -- The best way to get a good answer is to ask a good question. David Filmer (http://DavidFilmer.com) -- To unsubscribe, e-mail: [

Re: Bubble sort...

2007-10-10 Thread Matthew Whipple
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 tr

Re: Bubble sort...

2007-10-10 Thread Rob Dixon
[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 $ele

Re: Bubble sort...

2007-10-10 Thread Tom Phoenix
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 th