In my example, I have done to use the first (left-most) element of the given list is selected as the pivot.
(在我的示例中,我已完成将给定列表的第一个(最左侧)元素用作枢轴的选择。)
qsort([],[]):- !.
qsort([Pivot|Tail],Sorted):-
split(Pivot,Tail,Less,Greater),
qsort(Less,SortedLess),
qsort(Greater,SortedGreater),
append(SortedLess,[Pivot|SortedGreater],Sorted).
split(_,[],[],[]).
split(Pivot,[X|T],[X|Less],Greater):-
X=<Pivot,split(Pivot,T,Less,Greater).
split(Pivot,[X|T],Less,[X|Greater]):-
X>Pivot,split(Pivot,T,Less,Greater).
However, I am wondering how to use the second element as pivot
(但是,我想知道如何使用第二个元素作为枢轴)
ask by SkaraBrae translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…