Re: bubblesort
From: flapper (nobody_at_a.b.c.dINVALID)
Date: 04/24/04
- Previous message: Craig Lefler: "Visual Prolog V5.2."
- In reply to: Alan Bal jeu: "Re: bubblesort"
- Next in thread: Nameless: "Re: bubblesort"
- Reply: Nameless: "Re: bubblesort"
- Reply: flapper: "Re: bubblesort"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
=:
- Previous message: Craig Lefler: "Visual Prolog V5.2."
- In reply to: Alan Bal jeu: "Re: bubblesort"
- Next in thread: Nameless: "Re: bubblesort"
- Reply: Nameless: "Re: bubblesort"
- Reply: flapper: "Re: bubblesort"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|