Creation of arrays with complex types

This is a discussion on Creation of arrays with complex types within the Eiffel forums in Programming Languages category; 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...

Go Back   Application Development Forum > Programming Languages > Eiffel

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 10-24-2007, 12:40 PM
=?ISO-8859-1?Q?Roman_T=F6ngi?=
Guest
 
Default Creation of arrays with complex types

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
Reply With Quote
  #2  
Old 10-24-2007, 04:08 PM
Jean RUPPERT
Guest
 
Default Re: Creation of arrays with complex types

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

Reply With Quote
  #3  
Old 10-24-2007, 05:31 PM
=?ISO-8859-1?Q?Roman_T=F6ngi?=
Guest
 
Default Re: Creation of arrays with complex types

Works fine.

Thx
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:52 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.