material/Beiträge/DDI-Vortrag 2/Source/sources/bubblesort.prolog

8 lines
231 B
Prolog
Raw Normal View History

bubbleup([X, Y|L], [Y, X|L]) :- X > Y.
bubbleup([Z|L], [Z|ZL]) :- bubbleup(L, ZL).
bubblesort([], []).
bubblesort(L, SL) :- bubbleup(L, ZL), !, bubblesort(ZL, SL).
bubblesort(SL, SL).
?-bubblesort([7,9,1,2,3,6,4,5,8,0], SL).