[erlang-questions] Bucket Sort
Colm Dougan
colm.dougan@REDACTED
Thu May 21 03:33:20 CEST 2009
On Thu, May 21, 2009 at 12:20 AM, tonakai <aykutsoysal@REDACTED> wrote:
> Hi,
> i am a erlang newbie and trying to implement bucket sort, but i am stuck at
> the beginning because I can't figure out a way to divide the list into small
> buckets, i try to use accumulators but number of buckets is not fixed, i
> think i need to find a way to populate lists of lists.
> also i am thinking for concurrent version of it, but its also same problem,
> i need to send the number to the correct bucket (process).
> any ideas?
Can you give an example of the type of data you are working with?
Typically the 'dict' module is useful for grouping things, e.g. :
List =
[1,2,3,3,4,4,4,5,6,6,7,8,9,10,10,11],
D1 =
lists:foldl(
fun(El, Acc) ->
Bucket = (3 * (El div 3)),
dict:append(Bucket, El, Acc)
end,
dict:new(),
List
),
io:format("~p~n", [dict:to_list(D1)]),
Colm
More information about the erlang-questions
mailing list