Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
24
Task/Quickselect-algorithm/Erlang/quickselect-algorithm.erl
Normal file
24
Task/Quickselect-algorithm/Erlang/quickselect-algorithm.erl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
-module(quickselect).
|
||||
|
||||
-export([test/0]).
|
||||
|
||||
|
||||
test() ->
|
||||
V = [9, 8, 7, 6, 5, 0, 1, 2, 3, 4],
|
||||
lists:map(
|
||||
fun(I) -> quickselect(I,V) end,
|
||||
lists:seq(0, length(V) - 1)
|
||||
).
|
||||
|
||||
quickselect(K, [X | Xs]) ->
|
||||
{Ys, Zs} =
|
||||
lists:partition(fun(E) -> E < X end, Xs),
|
||||
L = length(Ys),
|
||||
if
|
||||
K < L ->
|
||||
quickselect(K, Ys);
|
||||
K > L ->
|
||||
quickselect(K - L - 1, Zs);
|
||||
true ->
|
||||
X
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue