Linked Lists in Linked Lists

Everything else that doesn't fall into one of the other PB categories.
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Linked Lists in Linked Lists

Post 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
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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...
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post 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
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post 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
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post 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
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post by Shopro »

freedimension:
Thanks for the advice. I have zero knowledge on SQLite, so I'll google it!

-Shopro
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post 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
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post 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
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post by Shopro »

Tinman:

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

Thanks again :)

-Shopro
User avatar
oryaaaaa
Addict
Addict
Posts: 831
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Post by oryaaaaa »

-Shopro
Pleses read PM. (jaPBe Bug report, Website)
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Another way to go

Post 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.
has-been wanna-be (You may not agree with what I say, but it will make you think).
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post 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
Post Reply