qsort([],[]). qsort([X|Xs],R) :- partition(Xs,X,L,R), qsort(L,SL), qsort(R,SR), append(SL,[X|SR],R). partition([],_,[],[]). partition([E|R],C,[E|L1],R) :- E=<C, !, partition(R,C,L1,R). partition([E|R],C,L,[E|R1]) :- E>C, !, partition(R,C,L,R1).
qsort(I,O) :- qsort(I,O,[]). qsort([],S,S). qsort([X|Xs],S,S2) :- partition(Xs,X,L,R), qsort(L,S,[X|S1]), qsort(R,S1,S2).