Re: bubblesort

From: flapper (nobody_at_a.b.c.dINVALID)
Date: 04/24/04

  • Next message: Nameless: "Re: bubblesort"
    Date: Sat, 24 Apr 2004 08:20:41 GMT
    
    

    Alan Bal jeu wrote:
    > "flapper" <not@a.b.c.dINVALID> wrote in message
    > news:3Hhic.7814$Fo4.97117@typhoon.sonic.net...
    >
    >>Would anyone care to comment on
    >>the relative advantages/disadvantages
    >>and/or desirability/undesirability of
    >>the two versions of bubblesort shown below?
    >
    >
    > Bubblesort is never desirable.

    > In fact though, the second algorithm looks like insertion sort,
    > which is better than bubblesort.
    >

       Egad, I forgot the difference between the two -- and somewhere along
    the way took to calling insertion sort "bubblesort".

      The "!" after the call to 'swap' still bothers me, however:

    bubblesort(List,Sorted) :-
         swap(List,PartSorted),!,
         bubblesort(PartSorted,Sorted).
    bubblesort(L,L).

    swap([X,Y|Tail],[Y,X|Tail]):-
         gt(X,Y).
    swap([X,Y|Tail],[X|Rest]) :-
         not( gt(X,Y) ),
         swap([Y|Tail],Rest).

    > As to style, both are hard to read due to lack of indentation.
    > All stuff following the :- should be indented a few spaces so
    > one can see where the predicates start and stop easier.
    >
    >

      Sorry, the tabs (^I) seem to have got lost in transmission.

      Thanks.

      =:


  • Next message: Nameless: "Re: bubblesort"

    Relevant Pages

    • Re: bubblesort
      ... > Would anyone care to comment on ... > the relative advantages/disadvantages ... Bubblesort is never desirable. ... both are hard to read due to lack of indentation. ...
      (comp.lang.prolog)
    • Re: bubblesort
      ... > Alan Bal jeu wrote: ... >> In fact though, the second algorithm looks like insertion sort, ... >> which is better than bubblesort. ...
      (comp.lang.prolog)