Afficher un message
Vieux 17/10/2007, 04h07   #7
user923005
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Selection sort and bubble sort

On Oct 16, 7:15 pm, "lovecreatesbea...@gmail.com"
<lovecreatesbea...@gmail.com> wrote:
> On Oct 17, 9:57 am, pete <pfil...@mindspring.com> wrote:
>
>
>
>
>
> > Eric Sosman wrote:

>
> > > lovecreatesbea...@gmail.com wrote On 10/16/07 15:32,:
> > > > Selection sort and bubble sort have same performance always, right?

>
> > > <off-topic> Wrong. </off-topic>

>
> > > > Are the following correctly implemented the both functions. Comments
> > > > are welcome.

>
> > > > Selection sort an array of intergers range between index l and r in
> > > > ascending order. For example, sort "312" into "123"

>
> > > > void sort_sel(int a, int l, int r)
> > > > {
> > > > int i, j, n;

>
> > > > for (i = l; i < r; i++)
> > > > for (j = i + 1; j <= r; j++)
> > > > if (a[i] > a[j]){
> > > > n = a[i];
> > > > a[i] = a[j];
> > > > a[j] = n;
> > > > }
> > > > }

>
> > > <off-topic> This is a bubble sort, implemented
> > > inefficiently even by B.S. standards. </off-topic>

>
> > > > Bubble sort an array of intergers range between index l and r in
> > > > ascending order. For example, sort "312" into "123"

>
> > > > void sort_bub(int a, int l, int r)
> > > > {
> > > > int i, n;

>
> > > > for (; l < r; r--)
> > > > for (i = l; i < r; i++)
> > > > if (a[i] > a[i + 1]){
> > > > n = a[i];
> > > > a[i] = a[i + 1];
> > > > a[i + 1] = n;
> > > > }
> > > > }

>
> > > <off-topic> This is also a bubble sort, whose
> > > implementation efficiency rivals that of the first
> > > example. </off-topic>

>
> > > Did you have a C question?

>
> > int a, should probably be int *a, instead.

>
> Yes, they're removed carelessly when the code was posted.


As a rule of thumb, don't post anything here until it compiles or
until you are simply unable to figure out why it won't compile.
In the latter case, point out "I can't get this code to compile --
what's wrong with it?" or something like that.

When you do get the code to compile, simply copy and paste the working
code into your browser or news client. It is far less error prone
than retyping and considerably easier also.

  Réponse avec citation
 
Page generated in 0,05654 seconds with 9 queries