Sorry, I have not been coding in the wonderful eiffel language
since some time, so it might be impossible to compile what I write,
but I think a loop will do the job:
bucket_sort is
-- Sort array.
local
buckets: ARRAY [LINKED_LIST [G]]
bucket: LINKED_LIST [G]
i,last: INTEGER
do
last:=4 -- last could also be set by another
-- method and not be local
create buckets.make (0,last)
from i:=0 until i>last
loop
create bucket.make
buckets.item(i) := bucket
end --loop
end --bucket_sort
Roman Töngi a écrit :
> Is it possible to create an ARRAY [LINKED_LIST [G]] more elegantly in a
> single step? If the number of array-elements is not known in advance, is
> there a dynamic version?
>
> bucket_sort is
> -- Sort array.
> local
> buckets: ARRAY [LINKED_LIST [G]]
> bucket_0: LINKED_LIST [G]
> bucket_1: LINKED_LIST [G]
> bucket_2: LINKED_LIST [G]
> bucket_3: LINKED_LIST [G]
> bucket_4: LINKED_LIST [G]
> do
> create buckets.make (0, 4)
> create bucket_0.make
> create bucket_1.make
> create bucket_2.make
> create bucket_3.make
> create bucket_4.make
> buckets.item (0) := bucket_0
> buckets.item (1) := bucket_1
> buckets.item (2) := bucket_2
> buckets.item (3) := bucket_3
> buckets.item (4) := bucket_4
> end
>
>
> Many thanks
> Roman


|