Prolog Bubblesort

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Prolog Bubblesort

    Hier 3 verschiedene Bubblesort Codes für Prolog

    Quellcode

    1. bubblesort(L_In,L_Out):-
    2. append(L_Front, [A, B|Rest], L_In),
    3. B < A,!,
    4. append(L_Front, [B, A|Rest], L_Rest),
    5. bubblesort(L_Rest, L_Out).
    6. bubblesort(Liste, Liste).




    Quellcode

    1. bubblesort(Xs,Xs):- geordnet(Xs).
    2. bubblesort(Xs,Ys):-
    3. append(As,[X,Y|Rs],Xs),
    4. X>Y,
    5. append(As,[Y,X|Rs],Xs1),
    6. bubblesort(Xs1,Ys).




    Quellcode

    1. bubble_sort(List,Sorted):-bubblesort(List,[],Sorted).
    2. bubblesort([],Acc,Acc).
    3. bubblesort([H|T],Acc,Sorted):-bubble(H,T,NT,Max),bubblesort(NT,[Max|Acc],Sorted).
    4. bubble(X,[],[],X).
    5. bubble(X,[Y|T],[Y|NT],Max):-X>Y,bubble(X,T,NT,Max).
    6. bubble(X,[Y|T],[X|NT],Max):-X=<Y,bubble(Y,T,NT,Max).