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* th

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 foll

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 u

Re: Bubble sort...

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

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 c

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 cl

Bubble sort...

2007-10-10 Thread [EMAIL PROTECTED]
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 (@ar

Re: What is "bubble sort"?

2001-11-16 Thread Paul Johnson
On Thu, Nov 15, 2001 at 05:22:26PM -0800, Curtis Poe wrote: > --- Sidharth Malhotra <[EMAIL PROTECTED]> wrote: > > While were on this, I'm taking an intro to Data Structures class and > > were learning all about the different sorting methods ... Insertsort, > > mergesort etc. What kind of sorting

Re: What is "bubble sort"?

2001-11-16 Thread Jeff 'japhy' Pinyan
On Nov 16, Pete Emerson said: >Multidimensional syntax $table[substr $_, $i, 1] not supported at ./sort3.pl line 31. That's bizarre. $table[substr($_, $i, 1)] might fix that. >and when I turn on strict: Gah. I've got working code on PerlMonks.org, with the name "IP Address Sorting". --

Re: What is "bubble sort"?

2001-11-16 Thread Pete Emerson
Okay, so I'm trying to implement your radix sort, and something's going wrong. When I turn on warnings (I'm using Perl v5.6.0) I get: Multidimensional syntax $table[substr $_, $i, 1] not supported at ./sort3.pl line 31. and when I turn on strict: Can't use an undefined value as an ARRAY reference

Re: What is "bubble sort"?

2001-11-16 Thread Etienne Marcotte
Pete Emerson wrote: > > Dave Storrs wrote: > > > Hmmm...this is interesting. A friend of mine who is in the > > process of getting her graduate degree in CS/information theory stuff > > recently told me that it has been mathematically proven that no sort can > > run faster than O(n log

Re: What is "bubble sort"?

2001-11-16 Thread Pete Emerson
Dave Storrs wrote: > Hmmm...this is interesting. A friend of mine who is in the > process of getting her graduate degree in CS/information theory stuff > recently told me that it has been mathematically proven that no sort can > run faster than O(n log n) unless you know something about

Re: What is "bubble sort"?

2001-11-16 Thread Dave Storrs
On Fri, 16 Nov 2001, Pete Emerson wrote: > I got this from http://www.wikipedia.com/wiki/Radix_sort: > > QUOTE > Radix sort is a sort algorithm that operates in O(n) time. This algorithm was > orignally > used to sort punched cards in several passes. It has resurfaced as an > alternative to > o

Re: What is "bubble sort"?

2001-11-16 Thread Pete Emerson
Jeff 'japhy' Pinyan wrote: > Ooh, radix sort. This is a cool technique, but it has a drawback: it > always runs in the same time. Sorting sorted data takes as long as > sorting UNsorted data. (Or sordid data!) I love the implementation, gotta examine it closely and your example by hand with

Re: What is "bubble sort"?

2001-11-16 Thread bill thater
Jeff 'Japhy' Pinyan wrote: > > Bubble sort is a naive sorting algorithm. It's called "bubble" sort > because the larger elements "rise" to the "top" of the list, like a bubble dang, that's the best explanation i've seen.

Re: What is "bubble sort"?

2001-11-16 Thread Jeff 'japhy' Pinyan
On Nov 16, Pete Emerson said: >Since we're on the topic of sorts, what are the arguments for >the implemented quicksort vs. a radix sort? (Perl now uses some mergesort hybrid.) Ooh, radix sort. This is a cool technique, but it has a drawback: it always runs in the same time. Sorting sorted d

Re: What is "bubble sort"?

2001-11-16 Thread Pete Emerson
Since we're on the topic of sorts, what are the arguments for the implemented quicksort vs. a radix sort? Pete -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: What is "bubble sort"?

2001-11-16 Thread John W. Krahn
Andrea Holstein wrote: > > "John W. Krahn" wrote: > > > That looks like a direct translation of algorithm 5.2.2B from TAoCP Vol. > > 3 however the usual implementation is more like Sedgewick's example: > > > > sub bubble { > > my $a = shift; > > > > for ( my $i = @$a; $i >= 1; $i-- ) { >

Re: What is "bubble sort"?

2001-11-16 Thread Andrea Holstein
"John W. Krahn" wrote: > That looks like a direct translation of algorithm 5.2.2B from TAoCP Vol. > 3 however the usual implementation is more like Sedgewick's example: > > sub bubble { > my $a = shift; > > for ( my $i = @$a; $i >= 1; $i-- ) { > for ( my $j = 2; $j <= $i; $j++ )

Re: What is "bubble sort"?

2001-11-16 Thread John W. Krahn
Jeff 'Japhy' Pinyan wrote: > > (Cross-posted to the Perl Beginners List) > > On Nov 15, Tommy Butler said: > > >What's a "bubble sort" ? I believe I heard the term used on this list a > >while back. I have some kind of idea of what it is,

RE: What is "bubble sort"?

2001-11-15 Thread Curtis Poe
--- Sidharth Malhotra <[EMAIL PROTECTED]> wrote: > While were on this, I'm taking an intro to Data Structures class and > were learning all about the different sorting methods ... Insertsort, > mergesort etc. What kind of sorting method perl's sort() use? > > Sid. Sid, Perl's sort function is

RE: What is "bubble sort"?

2001-11-15 Thread Sidharth Malhotra
IL PROTECTED]] Sent: Thursday, November 15, 2001 7:39 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: What is "bubble sort"? (Cross-posted to the Perl Beginners List) On Nov 15, Tommy Butler said: >What's a "bubble sort" ? I believe I heard the term used on thi

What is "bubble sort"?

2001-11-15 Thread Jeff 'japhy' Pinyan
(Cross-posted to the Perl Beginners List) On Nov 15, Tommy Butler said: >What's a "bubble sort" ? I believe I heard the term used on this list a >while back. I have some kind of idea of what it is, and how it would be >implemented, but I'd like to find out for