Lists containing lists
BlitzMax Forums/BlitzMax Beginners Area/Lists containing lists
| ||
| I'm getting muddled up on how to maintain a list where each entry holds a unique list of other items. Something like this for example:
butchers
> sausages
> beef
> pork
bakers
> bread
> cakes
> buns
post office
> stamps
> envelopes
> stationery
How do I approach this? So far I have this prototype but I'm a stuck on how to link a list of products to a shop from a list ... shoplist:TList=CreateList() Type shop Field shoptype$ Field productlist:TList ?????????? End Type Global s:shop s=New shoptype s.shoptype$="butchers" |
| ||
shop_list:TLIST = new TLIST
type Shop
field shop_type:string
field product_list:TLIST
method new ()
shop_list.addlast (self)
product_list = new TLIST
end method
method add_product (_name:string)
product_list.addlast (product.create(_name))
end method
end type
type product
field name:string
function create:product (_name:string)
local t:product = new product
t.name = _name
return t
end function
end type
global s:shop = new shop
s.shop_type = "butchers"
s.add_product = "sausages"
|
| ||
| I found a way which is much the same as yours it seems. Thanks for the quick response! ... Framework brl.linkedlist Import brl.standardio Global shoplist:TList=New TList Type shop Field shoptype$ Field productlist:TList=New TList Method New() ListAddLast shoplist,Self End Method Method AddProduct(productname$) p=New producttype p.name$=productname$ ListAddLast productlist,p End Method End Type Global s:shop Type producttype Field name$ End Type Global p:producttype ' =================================== s=New shop s.shoptype$="The Butchers" s.AddProduct "Sausages" s.AddProduct "Bacon" s.AddProduct "Pork" s=New shop s.shoptype$="The Bakers" s.AddProduct "Bread" s.AddProduct "Cakes" s.AddProduct "Buns" s=New shop s.shoptype$="Post Office" s.AddProduct "Stamps" s.AddProduct "Envelopes" s.AddProduct "Stationery" ' show lists For s=EachIn shoplist Print s.shoptype$ For p=EachIn s.productlist Print " > "+p.name$ Next Next |