Structures in Linked-Lists

Linked-lists are very powerful and can allow for very complicated data storage. Now let's see how it possible to store a different structure type inside each list node.First we need to create our list node:

List(l$);
Add(l$);

We now have one list node in l$ and our current internal pointer is placed on that first node.

We can now define the variable type like we would with any other variable:

struct(l$, “a”, “b”);
l.a$ = 10;
l.b$ = 20;

We can now add a new node and store another structure into it:

Add(l$);
struct(l$, “c”, “d”);
l.c$ = 30;
l.d$ = 40;

Now let's iterate through the list and output the structure's element values:

ForEach(l$)
if (Lpos(l$) == 0)
ShowMessage(l.a$);
ShowMessage(l.b$);
else if (Lpos(l$) == 1)
ShowMessage(l.c$);
ShowMessage(l.d$);
end;
end;


The Lpos() function returns the current pointer position of the list always starting with 0.

Imagine the possibilities offered by such flexibility.