Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.37 KB | None | 0 0
  1. quicksort([X|Xs],Ys) :-
  2.   partition(Xs,X,Left,Right),
  3.   quicksort(Left,Ls),
  4.   quicksort(Right,Rs),
  5.   append(Ls,[X|Rs],Ys).
  6. quicksort([],[]).
  7.  
  8. partition([X|Xs],Y,[X|Ls],Rs) :-
  9.   X <= Y, partition(Xs,Y,Ls,Rs).
  10. partition([X|Xs],Y,Ls,[X|Rs]) :-
  11.   X > Y, partition(Xs,Y,Ls,Rs).
  12. partition([],Y,[],[]).
  13.  
  14. append([],Ys,Ys).
  15. append([X|Xs],Ys,[X|Zs]) :- append(Xs,Ys,Zs).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement