Page 1 of 1

Linked Lists in Linked Lists

Posted: Mon May 03, 2004 2:51 pm
by Shopro
Hello PBers,

I have a question.

I'm trying to build a simple POS(Point of Sales) system for a Pizza store, and
in this system, an "Item"(Pizza) consists of numerous "Toppings"(Dough, Salami, Cheese).

My Topping structure is something like this:

Code: Select all

Structure Structure_Topping
  Name$
  AbrrName$
  WeightUnit$
  CostPerWeightUnit.w
EndStructure
Since an Item consists of an n number of Toppings(Don't know how many),
what makes sense to me is to have an a "ToppingsInItem" structure linked list, inside a Item structure linked list.

Maybe something like this:

Code: Select all

Structure_Item
  Name$
  Description$
  ChargeForItem.w
  NumOfToppings.w
  ItemDisabled.b
  IncludeToppings.w ; Number of Toppings to include for free
  
  Structure_ToppingsInItem
    Number.w
    Type.w
    AllowHalf.b
    AllowDouble.b
    WtWhole.w
    ChargeWhole.w
    WtHalf.w
    ChargeHalf.w
    WtDouble.w
    ChargleDouble.w
  EndStructure
EndStructure
(Yes, I know a structure in a structure isn't allowed)

Is having a linked list inside a linked list possible?
Or, is this method of handling toppings and items even good?


I'm asking, because the examples I found in the Code Archive,
to have linked lists inside linked lists seemed pretty complex,
and maybe there is a simpler way.

Any comments or advice will be appreciated, thanks:)

-Shopro

Posted: Mon May 03, 2004 3:11 pm
by Flype
perhaps you can do it this way :

Code: Select all

#MaxToppings = 10 ; what you want

Structure ToppingsInItem
  
  Number.w
  Type.w
  AllowHalf.b
  AllowDouble.b
  WtWhole.w
  ChargeWhole.w
  WtHalf.w
  ChargeHalf.w
  WtDouble.w
  ChargleDouble.w
  
EndStructure

Structure Item

  Name.s
  Description.s
  ChargeForItem.w
  NumOfToppings.w
  ItemDisabled.b
  IncludeToppings.ToppingsInItem[#MaxToppings]
  
EndStructure


NewList Items.Item()

AddElement(items())
items()\IncludeToppings[0]\Type=1
Debug items()\IncludeToppings[0]\Type
THIS is NOT a linkedlist in another one but it's an easy way
and i assume there's not an infinite list of Toppings...

Posted: Mon May 03, 2004 4:30 pm
by fweil
Shopro,

Maybe a way to point this ...

Code: Select all

Structure Component
  S1L1.l
  S1L2.l
  S1S1.s
EndStructure

Structure Components
  Components.Component[10]
EndStructure

Structure Struct2
  S2L1.l
  S2L2.l
  S2S1.s
  MyComponents.Components
EndStructure

NewList a.Struct2()

AddElement(a())

a()\S2L1 = 1
a()\S2L2 = 2
a()\S2S1 = "First record"
a()\MyComponents\Components[0]\S1L1 = 3
a()\MyComponents\Components[0]\S1L2 = 4
a()\MyComponents\Components[0]\S1S1 = "First component"

a()\MyComponents\Components[1]\S1L1 = 5
a()\MyComponents\Components[1]\S1L2 = 6
a()\MyComponents\Components[1]\S1S1 = "Second component"

a()\MyComponents\Components[2]\S1L1 = 7
a()\MyComponents\Components[2]\S1L2 = 8
a()\MyComponents\Components[2]\S1S1 = "Third component"

a()\MyComponents\Components[3]\S1L1 = 9
a()\MyComponents\Components[3]\S1L2 = 10
a()\MyComponents\Components[3]\S1S1 = "Fourth component"

ResetList(a())

NextElement(a())

Debug Str(a()\S2L1) + " " + Str(a()\S2L2) + " " + a()\S2S1 + " " + Str(a()\MyComponents\Components[0]\S1L1) + " " + Str(a()\MyComponents\Components[0]\S1L2) + " " + a()\MyComponents\Components[0]\S1S1
Debug Str(a()\S2L1) + " " + Str(a()\S2L2) + " " + a()\S2S1 + " " + Str(a()\MyComponents\Components[1]\S1L1) + " " + Str(a()\MyComponents\Components[1]\S1L2) + " " + a()\MyComponents\Components[1]\S1S1
Debug Str(a()\S2L1) + " " + Str(a()\S2L2) + " " + a()\S2S1 + " " + Str(a()\MyComponents\Components[2]\S1L1) + " " + Str(a()\MyComponents\Components[2]\S1L2) + " " + a()\MyComponents\Components[2]\S1S1
Debug Str(a()\S2L1) + " " + Str(a()\S2L2) + " " + a()\S2S1 + " " + Str(a()\MyComponents\Components[3]\S1L1) + " " + Str(a()\MyComponents\Components[3]\S1L2) + " " + a()\MyComponents\Components[3]\S1S1

Rgrds

Posted: Mon May 03, 2004 5:18 pm
by Shopro
fweil & Flype:

Thanks for the advice and code.

The idea of using a structure array instead of another linked list didn't occur to me.

I'd like to do a bit more research if I there is a easy way to implement an unlimited number of toppings in an Item,

and if nothing is as simple as the above ways, I'll use it :D

So, using the simple PB list commands, there is no way to have linked lists in a linked list?

Thanks again for the code

-Shopro

Posted: Mon May 03, 2004 5:40 pm
by freedimension
I'm using SQLite with a similar project and it's working fine.
You don't have to keep all the data the whole time in memory, do you?
And SQLite is damn fast :D

Posted: Mon May 03, 2004 7:58 pm
by Shopro
freedimension:
Thanks for the advice. I have zero knowledge on SQLite, so I'll google it!

-Shopro

Posted: Tue May 04, 2004 12:18 pm
by tinman
So, using the simple PB list commands, there is no way to have linked lists in a linked list?
I rewrote some linked list commands to be similar to the real PB commands to have linked lists inside linked lists. It should be on the http://www.purearea.net or resources site (wherever the hell that is these days) sites somewhere.

I haven't tested it with the latest 3.90 though.

Posted: Tue May 04, 2004 1:53 pm
by Shopro
Hi Tinman,

Is it in the User-Libs? Because I can't seem to find any Linked List+ lib.

Or, do you mean the Linked List code samples found in the CodeArchv?

-Shopro

Posted: Tue May 04, 2004 2:45 pm
by tinman
It was a piece of PB code, not a user lib - sorry for the ambiguity. It could be that sample on the code archive. If you can't find it I'll stick it on my website later today.

Posted: Tue May 04, 2004 6:49 pm
by Shopro
Tinman,

I found a linked list in linked list sample in the CodeArchv by NicTheQuick, but can't find any by you. I'd like to see yours as well, so posting it on the forum would be appreciated :).

-Shopro

Posted: Tue May 04, 2004 10:02 pm
by tinman
OK. You can find it on my website already, I had forgot that it was already there :)

Click here to download it. I'll post the code in the tricks and tips section also unless it's too big.

Posted: Wed May 05, 2004 1:14 am
by Shopro
Tinman:

Lots and lots of thanks, I'll be studying your code tonight!

Thanks again :)

-Shopro

Posted: Fri May 07, 2004 8:29 pm
by oryaaaaa
-Shopro
Pleses read PM. (jaPBe Bug report, Website)

Another way to go

Posted: Sun May 09, 2004 5:19 am
by oldefoxx
If you had a type in which you had a string called Toppings, you could expand the string to include each topping as ordered. If you used
unique abbreviations for each topping, the string could be kept reasonably
short, yet provide simple visual clues for debugging or tracing a process/order.

For instance, suppose Toppings used the following abbreviations:

THIN -thin crust
THICK -thick crust
CHEEZE -cheese
DBL -Double last item
GRNO -Green Olives
HAMB -Hamburger Meat
PEP -peperoni
BLKO -Black Olives
ANCH -Anchovies
GRNP -Green Peppers
ONION -Onions

And suppose the combinations were separated by semi-colons, so that the abbreviations could be anywhere from 1 character to as many as needed to represent a topping, then a tyical Toppings string might contain something like:

";CHEEZE;DBL;HAMB;POP;GRNP;"

parsing the Toppings string using the semi-colons means that each individual topping can be isolated and used to determine the quantity and
price for every individual pizza.

Posted: Sun May 09, 2004 5:18 pm
by Shopro
oryaaaa:
Get them, sorry for not noticing!

oldefoxx:
ahh, didn't think of that. That method would simplify things alot.

I especially liked the "DBL -Double last item" bit.

Thanks, I'll consider this method, and how I can implement it to work in my program.

Will notify if I decide to use it, thanks :)

-Shopro