Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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