-module(sort).
-export([sort/1]).
sort([]) -> [];
sort([PivotRest]) ->
{Smaller, Bigger} = split(Pivot, Rest),
lists:append(sort(Smaller), [Pivotsort(Bigger)]).
split(Pivot, L) ->
split(Pivot, L, [], []).
split(Pivot, [], Smaller, Bigger) ->
{Smaller, Bigger};
split(Pivot, [HdTl], Smaller, Bigger) when Hd <>
split(Pivot, Tl, [HdSmaller], Bigger);
split(Pivot, [HdTl], Smaller, Bigger) when Hd >= Pivot ->
split(Pivot, T, Smaller, [HdBigger]).
No comments:
Post a Comment